Skip to content

WebSocket data race in send path under backpressure#1160

Open
IvanArkhipov1999 wants to merge 2 commits into
CrowCpp:masterfrom
IvanArkhipov1999:write-buffer-mutex
Open

WebSocket data race in send path under backpressure#1160
IvanArkhipov1999 wants to merge 2 commits into
CrowCpp:masterfrom
IvanArkhipov1999:write-buffer-mutex

Conversation

@IvanArkhipov1999

Copy link
Copy Markdown

Hello!

When the server sends WebSocket messages faster than the client can read them, TCP backpressure appears and async writes take longer to complete.

At the same time, new messages are still pushed into Crow's outgoing buffer from another thread. As a result, one thread appends to the buffer while another thread swaps/reads it in do_write().

This causes a data race, buffer corruption, and eventually broken WebSocket frames on the client side (for example: "Invalid frame header").

I fixed the problem by protecting write_buffers_ with a mutex, and after that the issue disappeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant