-
Notifications
You must be signed in to change notification settings - Fork 497
Description
-
Version: latest
-
Subsystem: @libp2p/tcp
Severity: Low
Description
The hanging promise is to do with shutting down the tcp server
js-libp2p/packages/transport-tcp/src/listener.ts
Lines 364 to 372 in 1cbfd6c
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.
js-libp2p/packages/transport-tcp/src/listener.ts
Lines 306 to 308 in 1cbfd6c
this.connections.forEach(conn => { | |
conn.abort(err) | |
}) |
The connections are tracked in the onSocket listener method with the property this.connections.
js-libp2p/packages/transport-tcp/src/listener.ts
Lines 197 to 202 in 1cbfd6c
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.