-
Notifications
You must be signed in to change notification settings - Fork 8
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
Shutting down adapter #13
Comments
darrachequesne
added a commit
to socketio/socket.io
that referenced
this issue
Feb 23, 2024
darrachequesne
added a commit
that referenced
this issue
Mar 14, 2024
The fix (socketio/socket.io@bf64870) still isn't working. Currently I'm using this as a workaround:
|
@grobarko I was not able to reproduce the issue: import { Server } from "socket.io";
import { createAdapter } from "@socket.io/postgres-adapter";
import pg from "pg";
import process from "node:process";
const PORT = process.env.PORT || 3000;
const pool = new pg.Pool({
user: "postgres",
host: "localhost",
database: "postgres",
password: "changeit",
port: 5432,
});
await pool.query(`
CREATE TABLE IF NOT EXISTS socket_io_attachments (
id bigserial UNIQUE,
created_at timestamptz DEFAULT NOW(),
payload bytea
);
`);
pool.on("error", (err) => {
console.error("Postgres error", err);
});
const io = new Server({
adapter: createAdapter(pool)
});
io.on("connection", (socket) => {
socket.on("hello", () => {
// send to anyone except the sender
socket.broadcast.emit("hello", socket.id, process.pid);
});
});
io.listen(PORT);
console.log(`server listening on port ${PORT}`);
setTimeout(async () => {
console.log("STOP !!!");
io.close();
await pool.end();
}, 1000); See example here: https://github.com/socketio/socket.io/tree/main/examples/postgres-adapter-example Calling |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried shutting down socket IO with the adapter installed. The node js process won't exit, since there are still timers active.
I expect this to work:
There are still two timers running afterwards: the 30s cleanup timer and the ~2s reconnect timer
The workaround I found is:
The text was updated successfully, but these errors were encountered: