Skip to content
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

race condition causes @libp2p/tcp close method to hang #2760

Closed
tabcat opened this issue Oct 11, 2024 · 0 comments · Fixed by #2763
Closed

race condition causes @libp2p/tcp close method to hang #2760

tabcat opened this issue Oct 11, 2024 · 0 comments · Fixed by #2763
Labels
need/triage Needs initial labeling and prioritization

Comments

@tabcat
Copy link
Contributor

tabcat commented Oct 11, 2024

  • Version: latest

  • Subsystem: @libp2p/tcp

Severity: Low

Description

The hanging promise is to do with shutting down the tcp server

await new Promise<void>((resolve, reject) => {
this.server.close(err => {
if (err != null) {
reject(err)
return
}
resolve()
})

For server.close to resolve all socket connections must be closed.
The connections are closed inside of the close method.

this.connections.forEach(conn => {
conn.abort(err)
})

The connections are tracked in the onSocket listener method with the property this.connections.

this.log('new inbound connection %s', maConn.remoteAddr)
this.context.upgrader.upgradeInbound(maConn)
.then((conn) => {
this.log('inbound connection upgraded %s', maConn.remoteAddr)
this.connections.add(maConn)

The race condition is triggered when close is called before the connection is upgraded. At that point the socket is not added to this.connections.

Steps to reproduce the error:

https://github.com/tabcat/delay5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant