fix(sio): call adapter.init() when creating each namespace

The init() method of the adapter will now be called when creating a namespace with `io.of(<the-namespace>)`.

Note: any promise rejection is silently caught, as I don't see how we could properly expose the promise.

```js
const io = new Server({
  adapter: myAdapter
});
// under the hood, this:
// - implicitly creates the main namespace (/)
// - creates an instance of `myAdapter` for the main namespace
// - calls `myAdapter.init()` (with this change)
```

Related:

- https://github.com/socketio/socket.io/issues/3662
- https://github.com/socketio/socket.io-postgres-adapter/issues/16
This commit is contained in:
Damien Arrachequesne
2025-10-09 09:06:44 +02:00
parent e97549259e
commit f3e1f5ebdf

View File

@@ -197,6 +197,10 @@ export class Namespace<
_initAdapter(): void {
// @ts-ignore
this.adapter = new (this.server.adapter()!)(this);
Promise.resolve(this.adapter.init()).catch((err) => {
debug("error while initializing adapter: %s", err);
});
}
/**