Skip to content

[bug]: lnd state machine gets stuck for days leading to HTLC timeouts and force-closes #7682

Closed

Description

@TheBlueMatt

In the past few days I've observed two peers which went unresponsive on me after the commitment state machine did something nontrivial leading to stuck HTLCs for days and one force-close. On the other channel I disconnected+reconnected and the state machine picked back up and continued fine.

I'm waiting on positive version identification for the channel which force-closed, but the channel which I managed to resume had the following messages exchanged:

2023-05-06 18:53:45.864 TRACE [lightning::ln::peer_handler:1119] Enqueueing message UpdateAddHTLC
2023-05-06 18:53:45.864 TRACE [lightning::ln::peer_handler:1119] Enqueueing message CommitmentSigned

2023-05-06 18:56:14.413 TRACE [lightning::ln::peer_handler:1429] Received message RevokeAndACK

2023-05-06 18:56:14.477 TRACE [lightning::ln::peer_handler:1429] Received message CommitmentSigned # lnd peer should now be waiting on my RAA but otherwise happy

2023-05-06 18:56:14.532 TRACE [lightning::ln::peer_handler:1119] Enqueueing message UpdateAddHTLC
2023-05-06 18:56:14.532 TRACE [lightning::ln::peer_handler:1119] Enqueueing message UpdateAddHTLC
2023-05-06 18:56:14.532 TRACE [lightning::ln::peer_handler:1119] Enqueueing message UpdateAddHTLC
2023-05-06 18:56:14.532 TRACE [lightning::ln::peer_handler:1119] Enqueueing message CommitmentSigned

2023-05-06 18:56:14.532 TRACE [lightning::ln::peer_handler:1119] Enqueueing message RevokeAndACK # We're now expecting an RAA (of the previous commitment) and a response commitment_signed

2023-05-06 18:59:10.946 TRACE [lightning::ln::peer_handler:1429] Received message RevokeAndACK

2023-05-06 18:59:11.072 TRACE [lightning::ln::peer_handler:1429] Received message CommitmentSigned

2023-05-06 18:59:11.190 TRACE [lightning::ln::peer_handler:1119] Enqueueing message CommitmentSigned # we now want a n RAA in response to this which never comes

2023-05-06 18:59:11.190 TRACE [lightning::ln::peer_handler:1119] Enqueueing message RevokeAndACK

My counterparty indicated they're running LND 0.16.1-beta and

"There's only one line in the logs from that time relevant to our channel 2023-05-06 18:57:21.387 [ERR] HSWC: ChannelLink(ae8eb08347dfcf674392b22553e9cdb0a47c413bf12e0aa3087ee9cdbcaee623:1): failing link: unable to complete dance with error: remote unresponsive"

Activity

  1. added
    bug
    on May 9, 2023
  2. TheBlueMatt commented on May 9, 2023

    @TheBlueMatt
    Author

    Note that this socket was totally fine, and continued to ping+pong for a day or two before I manually restarted my node to disconnect/reconnect.

  3. TheBlueMatt commented on May 9, 2023

    @TheBlueMatt
    Author

    The other peer with which I saw this same behavior I have not confirmed was lnd (waiting to hear back), but had a much simpler state machine update hang:

    2023-05-06 18:57:00.793
            send update_add + CS
    2023-05-06 18:58:02.528
            receive update_fail(2083) + cs
    2023-05-06 18:58:02.543
            send response raa
    2023-05-06 18:58:02.543
            receive raa
    2023-05-06 18:58:02.559
            free holding cell htlcs, update_addx4 + cs (not containing 2083)
    2023-05-06 18:58:35.588
            send ping
    2023-05-06 18:58:35.789
            receive pong
    
  4. added
    commitments
    on May 9, 2023
  5. Roasbeef commented on May 9, 2023

    @Roasbeef
    Member

    The error message you saw above comes from here:

    lnd/htlcswitch/link.go

    Lines 1241 to 1244 in 8df4ede

    case <-l.cfg.PendingCommitTicker.Ticks():
    l.fail(LinkFailureError{code: ErrRemoteUnresponsive},
    "unable to complete dance")
    return

    We start a timer when ever we send out a new commit sig, and stop it after we're able to send another sig. So in practice, if the remote party doesn't send RAA, then this will be hit after a period of time.

    The default timeout for that is actually 1 minute, which seems pretty long:

    lnd/config.go

    Lines 190 to 193 in 8df4ede

    // defaultPendingCommitInterval specifies the default timeout value
    // while waiting for the remote party to revoke a locally initiated
    // commitment state.
    defaultPendingCommitInterval = 1 * time.Minute
    🤔

  6. TheBlueMatt commented on May 9, 2023

    @TheBlueMatt
    Author

    Hmm, that would imply (a) the peer is pretty slow, where that triggered five seconds late and (b) it didn't recognize my RAA at 2023-05-06 18:56:14.532 as being in response to its CS at 2023-05-06 18:56:14.477?

  7. TheBlueMatt commented on May 9, 2023

    @TheBlueMatt
    Author

    I mean obviously the peer is slow, it took almost 4 minutes to respond with an RAA at 2023-05-06 18:59:10.946.

  8. Roasbeef commented on May 15, 2023

    @Roasbeef
    Member

    Yeah re slowness, it could be their node is heavily loaded due to the perf bug introduced in v0.16.1. The load there will more or less scale as a function of the mempool load, which is still above the default cap for most nodes, and includes a ton of very small txns (1-in-1-out). If the peer upgrade, and also sets --bitcoind.txpollinginterval to like 5m (default is 1m), then their load should go down.

  9. TheBlueMatt commented on May 15, 2023

    @TheBlueMatt
    Author

    I don't really get how load explains this, the peer responded totally fine, but a bit slow, to a number of messages, and then didn't respond to anything else in the state machine for days across a live (ping+pong'ing just fine) socket. I guess if there's some goroutine prioritiy swap thing that is causing the state machine to go from operating to 100% starved it could?

  10. saubyk commented on May 17, 2023

    @saubyk
    Collaborator

    Hi @TheBlueMatt is it possible to get logs from your counterparty whose channel got force closed?

  11. wpaulino commented on May 17, 2023

    @wpaulino
    Contributor

    We start a timer when ever we send out a new commit sig, and stop it after we're able to send another sig. So in practice, if the remote party doesn't send RAA, then this will be hit after a period of time.

    It seems that the channel link gets torn down, but the connection doesn't, so a manual reconnection is required by either side to get the link active again. If neither node operator notices this, the channel can eventually go to chain due to some HTLC. Is there any reason a disconnect isn't done for this specific case?

  12. hazrulnizam commented on May 18, 2023

    @hazrulnizam

    Is this by any chance related to #6098?

    The same unable to complete dance log message appears in that issue.

  13. TheBlueMatt commented on May 18, 2023

    @TheBlueMatt
    Author

    Yep that's the same bug!

  14. added this to the v0.17.0 milestone on May 19, 2023
  15. Roasbeef commented on May 20, 2023

    @Roasbeef
    Member

    Hey turns out I was wrong here, and we don't disconnect when we enter this state like we should 🤦. Will fix this in an upcoming PR, thanks for the bug report!

  16. Roasbeef commented on May 20, 2023

    @Roasbeef
    Member

    @wpaulino

    Is there any reason a disconnect isn't done for this specific case?

    I think the prior assumption was that if the TCP connection was actually stale, then the read/write timeout would be hit and the connection recycled. We also support multiple channels per peer, so the idea then was that we should keep the connection alive as maybe this was just isolated to that particular channel state machine for w/e reason.

    Also the main motivation of adding the waaay back, was to ensure that any un ack'd messages in the mailbox were able to be canceled back (they didn't make it into an outgoing commit sig). AFAICT, this is properly happening, but if items actually made it out with a sig, then we'd enter this failure scenario.

  17. moved this to 👀 In review in lnd v0.17on May 21, 2023
  18. modified the milestones: v0.17.0, v0.16.3 on May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

HTLCbugcommitmentsforce closesneeds triage

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions