-
Notifications
You must be signed in to change notification settings - Fork 446
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
.stop()
sometimes hangs indefinitely
#2625
Comments
When the stop timeouts, I have one connection left with 0 streams, |
Closing the async _invokeStartableMethod(methodName) {
const timeout = new Promise((resolve, reject) => {
setTimeout(() => {
reject('timeout')
}, 10000);
});
const connectionManager = this.components["connectionManager"]
if (isStartable(connectionManager)) {
await connectionManager[methodName]?.();
}
let promise = Promise.all(Object.values(this.components)
.filter(obj => isStartable(obj))
.map(async (startable) => {
await startable[methodName]?.();
}));
const race = Promise.race([promise, timeout]);
try {
await race;
}
catch (e) {
throw e;
}
finally {
clearTimeout(timeout);
}
} |
I may be missing something but where is the
Looking at the code, the TCP listener aborts each connection on close whereas the WebSocket transport tries to close them gracefully. Do you still see the issue if the transport aborts the connections instead of closing them on close? |
/// it-ws/server.ts
async close (): Promise<void> {
await new Promise<void>((resolve, reject) => {
this.server.closeAllConnections()
this.server.close((err) => {
if (err != null) {
reject(err); return
}
resolve()
})
})
}
|
Actually the closeAllConnections trick does work since the connection is a The close connection manager first trick seems to always work. Also adding like a 5s delay before stopping also seems to work. It feels like there is some kind of connection creation in process that is not caught correctly on closing |
Aha, that's interesting, nice find. The docs do say though:
...so I wonder if there's something else going on here? |
Ye the whole thing about aborting Websocket connections before closing does not seem to have an impact. Only the two things I mentioned in my last comment did mitigate the problem for me |
That would explain something! |
Version:
1.8.1
Subsystem:
@libp2p/websocket , connection manager, components
Severity:
High
Description:
Steps to reproduce the error:
I have a test scenario with a few nodes that I connect to each other and send some data
Sometimes when terminating a node it endlessly waits for the Websocket transport to shutdown. This is because there are connections that does close (?) and in the
it-ws
library there are no calls toserver.closeAllConnections()
beforeclose
.I have managed to make the shutdown work better if modify
js-libp2p/packages/libp2p/src/components.ts
Line 72 in 73f2b6b
Also no issues if I use Tcp transport instead.
This is not a good description on how to reproduce the issue, because it is a bit random when it occurs. But wanted to create this issue if others have the same problem and will update the description if I have a isolated a good test
The text was updated successfully, but these errors were encountered: