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

Open
tabcat opened this issue Oct 11, 2024 · 0 comments · May be fixed by #2763
Open

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

tabcat opened this issue Oct 11, 2024 · 0 comments · May be 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

@tabcat tabcat added the need/triage Needs initial labeling and prioritization label Oct 11, 2024
@tabcat tabcat linked a pull request Oct 11, 2024 that will close this issue
3 tasks
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