closing old websocket server instances without errors

im trying to implement a ping pong logic combined with an ip rate limiter i created a Map() like so
// Retrieve or initialize ipInfo for this IP
const ipInfo = this.ipData.get(ip) || {
connection: [],
message: [],
pong: [],
initialPingTimeout: null,
pongReceived: false,
serverInstance: null
};
// Retrieve or initialize ipInfo for this IP
const ipInfo = this.ipData.get(ip) || {
connection: [],
message: [],
pong: [],
initialPingTimeout: null,
pongReceived: false,
serverInstance: null
};
trying to account for client attacks where they initiate multiple connection via. dev console. for example running const websocket = new WebSocket('ws://localhost:8787/websocket'); repeatedly. my ip rate limiter handles the spam. but how can i clean up the previous instantiated server without errors?
//handle previous server instance if exists
if(
ipInfo.serverInstance &&
ipInfo.serverInstance.readyState === 1 &&
ipInfo.serverInstance !== server
){
try{
console.log('before: ',ipInfo.serverInstance.readyState)
ipInfo.serverInstance.close(1000,'Closing previous connection')
console.log('after: ',ipInfo.serverInstance.readyState)
}catch(e){}
}
//assign current server instance to map
ipInfo.serverInstance = server

//...

this.ipData.set(ip, ipInfo);
//handle previous server instance if exists
if(
ipInfo.serverInstance &&
ipInfo.serverInstance.readyState === 1 &&
ipInfo.serverInstance !== server
){
try{
console.log('before: ',ipInfo.serverInstance.readyState)
ipInfo.serverInstance.close(1000,'Closing previous connection')
console.log('after: ',ipInfo.serverInstance.readyState)
}catch(e){}
}
//assign current server instance to map
ipInfo.serverInstance = server

//...

this.ipData.set(ip, ipInfo);
ipInfo.serverInstance.close works as expected but when client starts a new connection, server gets this error:
before: 1
after: 2
[wrangler:inf] GET /websocket 101 Switching Protocols (3ms)
✘ [ERROR] Uncaught (in response) Error: Network connection lost.


✘ [ERROR] workerd/server/server.c++:3069: error: Uncaught exception: kj/async.c++:212: disconnected: worker_do_not_log; Request failed due to internal error
before: 1
after: 2
[wrangler:inf] GET /websocket 101 Switching Protocols (3ms)
✘ [ERROR] Uncaught (in response) Error: Network connection lost.


✘ [ERROR] workerd/server/server.c++:3069: error: Uncaught exception: kj/async.c++:212: disconnected: worker_do_not_log; Request failed due to internal error
any way to get rid of this? i can't seem to find the source of this error. sorry for wall of post
S
sty118d ago
any help would be appreciated! ahh got answer from github
Sorry, workerd's logging is still very bad. The logging was actually not designed to be actionable to application developers, instead it was designed to be actionable to us -- the engineers working on workerd itself. For the time being I would recommend ignoring workerd logs unless you are seeing a problem separately and trying to debug it
Sorry, workerd's logging is still very bad. The logging was actually not designed to be actionable to application developers, instead it was designed to be actionable to us -- the engineers working on workerd itself. For the time being I would recommend ignoring workerd logs unless you are seeing a problem separately and trying to debug it