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
{{ message }}
Repository navigation
Transmit only single frame in Write when compression enabled too #435
Hi I am experiencing a pretty weird behavior and I am unsure if this is intentional or not.
We have had problems with bad client performance when reading data from a websocket in a game client based on Unreal Engine.
I have investigated this and with compression enabled each message is chopped up in tiny frames (the problem surfaced when we run with 1.8.7 which had compression on by default). The problem with Unreal is that it only reads one frame per client tick (~8 milliseconds) by default.
When I inspect this in Wireshark it looks like every other frame has a 236 byte payload and every other has a 4 byte payload.
I also run it in the debugger and it looks like the server will send a frame for each write call from the flate lib (github.com/klauspost/compress) and it has a hard coded bufferFlushSize set to 240 which in turn causes all those individual calls to writeFrame.
changed the title [-]Transmit single frame in Write when compression enabled too[/-][+]Transmit only single frame in Write when compression enabled too[/+]on Feb 21, 2024
Activity
nhooyr commentedon Feb 21, 2024
Are you using
WriteorWriter?Writeshould write in a single frame whereas Writer unfortunately does write in two frames.If you are using
Writeit's possible I forgot to add the code necessary to make it use a single frame with compression enabled.nhooyr commentedon Feb 21, 2024
Also are you using the latest version or are you on 1.8.7 still?
andersroos commentedon Feb 21, 2024
Thanks for the response.
I have tested on 1.8.10 and it is the same behavior if compression is enabled (
CompressionMode: websocket.CompressionNoContextTakeover).The code uses
Write(this method: https://github.com/nhooyr/websocket/blob/e3a2d32f704fb06c439e56d2a85334de04b50d32/write.go#L44).I can make a minimal example to reproduce if it's helpful.
nhooyr commentedon Feb 21, 2024
No need I see it, the problem is here: https://github.com/nhooyr/websocket/blob/e3a2d32f704fb06c439e56d2a85334de04b50d32/write.go#L110
I need to extend this code to allow for single frame compression.
[-]Tiny frames when compression is enabled[/-][+]Transmit single frame in Write when compression enabled too[/+][-]Transmit single frame in Write when compression enabled too[/-][+]Transmit only single frame in Write when compression enabled too[/+]nhooyr commentedon Feb 21, 2024
I would suggest disabling compression till I get to this. Hopefully within the next 2 months.
andersroos commentedon Feb 21, 2024
Thank you, will do.
fix: transmit in single frame when compression enabled
mafredri commentedon Dec 19, 2025
@andersroos, you've been waiting a while, but a fix was just merged in. No release yet, but it's there if you want to try it out.
andersroos commentedon Dec 19, 2025
Hey! Thank you!
Will test it for sure, but can't say if it will be before or after release yet.
fix: transmit in single frame when compression enabled (coder#552)
kornes commentedon Mar 13, 2026
I ran into exact same issue with compressed messages, and can confirm #552 pr fixed it for me 👍