socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

correctly await async close on adapters

Open marknelissen opened this issue 1 year ago • 3 comments

The kind of change this PR does introduce

  • [x] a bug fix
  • [ ] a new feature
  • [ ] an update to the documentation
  • [ ] a code change that improves performance
  • [ ] other

Current behavior

The close of the server does not await the async close operations of the adapters like the MongoAdapter, leading to errors due to premature closing of the underlying connection.

New behavior

The close awaits the async operations on the adapters of the different namespaces. This allows to be sure that e.g. the Mongo connection can be safely disposed of.

Other information (e.g. related issues)

I've chose the Promise.allSettled to avoid being too disruptive, since the current synchronous implementation already disregards any errors the closing of the adapters might raise.

marknelissen avatar Mar 11 '24 16:03 marknelissen

Hi! Thanks for the pull request :+1:

In that case, do you think it would make sense to wait for the completion of this.httpServer.close() below too?

Reference: https://nodejs.org/api/http.html#serverclosecallback

darrachequesne avatar Mar 13 '24 09:03 darrachequesne

That is already what is done. The only way to wait for it, is to pass the callback function, which the current code already does. It is not an awaitable function, since it does not return a Promise.

marknelissen avatar Mar 13 '24 11:03 marknelissen

@darrachequesne What else is needed to get this merged?

BrandonZacharie avatar Jul 02 '24 18:07 BrandonZacharie

@darrachequesne I resynced the branch. Can you approve?

marknelissen avatar Aug 30 '24 07:08 marknelissen

@marknelissen thanks :+1:

darrachequesne avatar Sep 14 '24 06:09 darrachequesne