Tristan
Tristan3y ago

Convex Client not exiting cleanly

I'm having trouble getting InternalConvexClient to exit cleanly. The following code hangs, even though I call client.close(). Am I missing something?
import { InternalConvexClient } from "convex/browser";
import WebSocket from "ws";

const url = "https://mellow-meerkat-454.convex.cloud";
const client = new InternalConvexClient(url, (queries) => {}, {
webSocketConstructor: WebSocket as any,
unsavedChangesWarning: false,
});

// Close after waiting a bit to ensure client has connected.
setTimeout(() => {
client.close().then(() => console.log("resolved client.close()"));
}, 2000);

process.on("exit", () => {
console.log("clean exit");
});
import { InternalConvexClient } from "convex/browser";
import WebSocket from "ws";

const url = "https://mellow-meerkat-454.convex.cloud";
const client = new InternalConvexClient(url, (queries) => {}, {
webSocketConstructor: WebSocket as any,
unsavedChangesWarning: false,
});

// Close after waiting a bit to ensure client has connected.
setTimeout(() => {
client.close().then(() => console.log("resolved client.close()"));
}, 2000);

process.on("exit", () => {
console.log("clean exit");
});
3 Replies
Tristan
TristanOP3y ago
It seems to take 28 seconds exactly to exit. If I close 10 seconds after starting, then it takes 20 seconds. So it appears there's some sort of 30 second heartbeat. The close promise resolves basically immediately though.
ballingt
ballingt3y ago
I can repro, so no you're not missing something (or I am too) This might be a regression due to some improvements to auth reconnection we made recently, regardless should be fixed in the release next week. Thank you for the report @Tristan! It's a timer, if you need a workaround for now you can use
const close = client => {
clearTimeout(client.webSocketManager.reconnectDueToServerInactivityTimeout);
return client.close();
};
const close = client => {
clearTimeout(client.webSocketManager.reconnectDueToServerInactivityTimeout);
return client.close();
};
Tristan
TristanOP3y ago
Awesome thanks!

Did you find this page helpful?