You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'll take your documentation example and tweak it a little for demonstration purposes
const Koa = require('koa')
const websocket = require('koa-easy-ws')
const app = new Koa()
app.use(websocket())
app.use(async (ctx, next) => {
if (ctx.ws) {
const ws = await ctx.ws() // retrieve socket
// here I hydrate ctx with some stuff
ctx.websocket = ws
ctx.client = authenticatedClient()
ctx.websocketSendJson = fantasticFunctionThatStringifiesAJsonAndSendsIt
ctx.websocket.on('message',()=>{ctx.websocketSendJson(amazingJson)})
ctx.websocket.on('close',()=>{doSomething()})
// hydration end
}
ctx.body = 'general kenobi'
})
As you can see, some of my application's middlewares hydrate ctx with some helpful stuff for authentication purposes for example.
The thing is that my application has some memory leaks, and I am suspicious about these ctx hydrators.
I am handling some stuff in the 'close' event of the websocket, for example, to close a connection that I opened to a third party message broker.
The thing is that I am not deleting or doing anything about these objects that I place in ctx. Should I?
As you can see in the example above, after the ws request is handled by registering all of those callbacks (on.close, on.message) and then the middleware returns. Later ctx stuff is still needed. So, when will it be freed? When the websocket closes? If so, why? Isn't it just another callback just like on.message and on.pong?
Please help me making this right. Thank you.
The text was updated successfully, but these errors were encountered:
Hello
I'll take your documentation example and tweak it a little for demonstration purposes
As you can see, some of my application's middlewares hydrate ctx with some helpful stuff for authentication purposes for example.
The thing is that my application has some memory leaks, and I am suspicious about these ctx hydrators.
I am handling some stuff in the 'close' event of the websocket, for example, to close a connection that I opened to a third party message broker.
The thing is that I am not deleting or doing anything about these objects that I place in ctx. Should I?
As you can see in the example above, after the ws request is handled by registering all of those callbacks (on.close, on.message) and then the middleware returns. Later ctx stuff is still needed. So, when will it be freed? When the websocket closes? If so, why? Isn't it just another callback just like on.message and on.pong?
Please help me making this right. Thank you.
The text was updated successfully, but these errors were encountered: