You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While diving into the privval package source code as part of an investigation into horcrux we discovered that the "accept connection logic" is unclear.
See source. Writing to the unbuffered channel sl.connectRequestCh after attempting to accept a connection in SignerListenerEndpoint.serviceLoop has no affect. This is because a single goroutine cannot read and write to the same unbuffered channel, it can only do that with buffered channels.
It would therefore be clearer to remove that select statement since it never actually writes to the channel.
If the reasoning behind the serviceLoop is to successfully accept one connection for each connectRequest then one could change connectRequestCh into a buffered channel with length 1 and only write to it when acceptNewConnection errored.
We'll need a bit of time to get a deep understanding of this issue since our team is working full capacity to deliver v0.38 this month. Thanks for the patience.
In the meantime, do I understand correctly that this issue does not translate into an incorrect behavior/defect (such as inability to accept conns), but it's more about code hygiene? If it's a defect, that will encourage us to prioritize it. Also, noticed you added unit tests here, but not sure I understand the logic; maybe there is also a recipe to reproduce the defect using a couple of nodes in practice?
Hi @adizere, at first I only thought it was a "code hygiene" issue. But then I realised that it is indeed a logic bug.
Basically, the serviceloop will not retry sl.acceptNewConnection() if it errors. It will only attempt acceptNewConnection once and if it errors, it will ignore the error and block waiting to another thread to call triggerConnect.
My understanding is that this can cause a "deadlock" with the node not accepting new connections anymore.
The problem with testing this "using couple of nodes in practice" is that you need net.Listener.Accept() to error to trigger this bug. In practice net.Listener.Accept() doesn't error. That is why I used a mock listener in the unit test that returns a few initial errors before successfully returning (err==nil).
Was suspecting that, thanks for clarifying! Too bad there's no reliable way to reproduce the bug. That would have given us a lot more confidence in the proposed changes. Give us some time to parse this, and we'll ping you re: potentially porting corverroos/tendermint#1 here.
Activity
corverroos commentedon Mar 3, 2023
I raised this with Tendermint but they routed me here: tendermint/tendermint#10009
I also created a PR in my local fork that I can move here if it looks good: corverroos/tendermint#1
adizere commentedon Mar 9, 2023
Nice find, thanks for reporting!
We'll need a bit of time to get a deep understanding of this issue since our team is working full capacity to deliver v0.38 this month. Thanks for the patience.
In the meantime, do I understand correctly that this issue does not translate into an incorrect behavior/defect (such as inability to accept conns), but it's more about code hygiene? If it's a defect, that will encourage us to prioritize it. Also, noticed you added unit tests here, but not sure I understand the logic; maybe there is also a recipe to reproduce the defect using a couple of nodes in practice?
corverroos commentedon Mar 10, 2023
Hi @adizere, at first I only thought it was a "code hygiene" issue. But then I realised that it is indeed a logic bug.
Basically, the
serviceloopwill not retrysl.acceptNewConnection()if it errors. It will only attemptacceptNewConnectiononce and if it errors, it will ignore the error and block waiting to another thread to calltriggerConnect.My understanding is that this can cause a "deadlock" with the node not accepting new connections anymore.
The problem with testing this "using couple of nodes in practice" is that you need
net.Listener.Accept()to error to trigger this bug. In practicenet.Listener.Accept()doesn't error. That is why I used a mock listener in the unit test that returns a few initial errors before successfully returning (err==nil).adizere commentedon Mar 10, 2023
Was suspecting that, thanks for clarifying! Too bad there's no reliable way to reproduce the bug. That would have given us a lot more confidence in the proposed changes. Give us some time to parse this, and we'll ping you re: potentially porting corverroos/tendermint#1 here.
fix(privval): retry accepting a connection on errors
fix(privval): retry accepting a connection on errors (#2047)
fix(privval): retry accepting a connection on errors (#2047)
fix(privval): retry accepting a connection on errors (#2047)
fix(privval): retry accepting a connection on errors (#2047)
fix(privval): retry accepting a connection on errors (backport #2047) (…