-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add refcounting to avoid close connection by mistake #77051
Conversation
ConnectedNodeRefCounter connectedNodeRefCounter = connectedNodes.get(node); | ||
if (connectedNodeRefCounter != null) { | ||
if (connectedNodeRefCounter.isDeleting) { | ||
connectedNodeRefCounter.incRef(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this will leak: we might call connectToNode
multiple times while the isDeleting
flag is set (e.g. handling multiple joins from the same node, or else an old PeerFinder
might still be active). We need to make sure that every connectToNode
call explicitly releases any references that it obtained.
I use It seems difficult to work out exactly when to release the |
Difficult, yes, but unfortunately it seems necessary too. I spent some time on this yesterday and although I'm not ready to open a PR you can see my work here: master...DaveCTurner:2021-09-01-releasable-connections. I think this gets the lifecycles about right, and I love how much it simplifies the |
The connection will be closed by
node-left
task, at the same time the connection maybe have been reused by join request, This commit import refcounting to solve the problem.Relates #67873