fastify-websocket icon indicating copy to clipboard operation
fastify-websocket copied to clipboard

fix: provide websocket instead of stream to avoid potential backpressure issues (#289)

Open mat-sz opened this issue 1 year ago • 5 comments

Now createWebSocketStream is not called therefore there are no memory leaks/backpressure to worry about.

Checklist

mat-sz avatar Mar 02 '24 20:03 mat-sz

@mcollina As discussed here https://github.com/fastify/fastify-websocket/issues/289#issuecomment-1973621926

I've removed stream creation completely. Another option here is to provide an object of shape { socket: WebSocket } to provide compatibility with most common use cases.

Also, could be nice to provide a function to convert that socket into a stream; so the object could even be { socket: WebSocket; getStream: (opts?: DuplexOptions) => Promise<Duplex> }.

I can update this PR to include either of the aforementioned solutions.

mat-sz avatar Mar 02 '24 20:03 mat-sz

I don't think having a specific function is needed, let's just document how to create it using ws.

mcollina avatar Mar 03 '24 09:03 mcollina

@mcollina I've added an example to README.md

mat-sz avatar Mar 04 '24 17:03 mat-sz

CI is failing

mcollina avatar Mar 07 '24 10:03 mcollina

@mcollina Resolved, for some reason the unit test was relying on the count of fastify log items to be constant, updated it to fail if level >= 50 instead.

mat-sz avatar Mar 07 '24 17:03 mat-sz