[ON-1531] socket.io: serialize websocket writes onto the socket-queue…#8
Open
RichardStoff wants to merge 1 commit into
Open
[ON-1531] socket.io: serialize websocket writes onto the socket-queue…#8RichardStoff wants to merge 1 commit into
RichardStoff wants to merge 1 commit into
Conversation
… thread On iOS (_SAL_TIME_H) socket.io has no asio network thread — all I/O runs on the single SocketQueueKpoll loop, which also processes inbound frames (onSocketMessage → handle_read_frame). A websocketpp connection is not internally locked: every operation on it must run on that one thread. client_impl::send_impl() called m_client.send(m_con, ...) inline on the caller's thread. emit*() runs on app threads and the ping runs on the timer thread, so a write could execute concurrently with SocketQueueKpoll inside handle_read_frame on the same connection. That race corrupts the connection's shared read/write state and crashes on the read side in sio::packet_manager::put_payload (EXC_BAD_ACCESS, faulting pointer holding inbound-payload bytes). The earlier teardown fix only serialized close/sync_close; the write path was still inline. All writers funnel through send_impl (only m_client.send call site; emit, ping, connect and on_encode all route through it), so hop the write onto the socket-queue thread there — inline when already on it (handshake sends from on_open), Post() otherwise. Inbound handling, writes and close now all run on the one thread. Reuses the existing SAL::MSocketQueueManager Post/IsOnQueueThread hooks; no ABI/layout change. Non-_SAL_TIME_H (asio) path unchanged — its io_service strand already serializes. Change-Id: Ie3a8260714ca008fc810436b10f8b9d325c5b3b1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… thread
On iOS (_SAL_TIME_H) socket.io has no asio network thread — all I/O runs on the single SocketQueueKpoll loop, which also processes inbound frames (onSocketMessage → handle_read_frame). A websocketpp connection is not internally locked: every operation on it must run on that one thread. client_impl::send_impl() called m_client.send(m_con, ...) inline on the caller's thread. emit*() runs on app threads and the ping runs on the timer thread, so a write could execute concurrently with SocketQueueKpoll inside handle_read_frame on the same connection. That race corrupts the connection's shared read/write state and crashes on the read side in sio::packet_manager::put_payload (EXC_BAD_ACCESS, faulting pointer holding inbound-payload bytes).
The earlier teardown fix only serialized close/sync_close; the write path was still inline. All writers funnel through send_impl (only m_client.send call site; emit, ping, connect and on_encode all route through it), so hop the write onto the socket-queue thread there — inline when already on it (handshake sends from on_open), Post() otherwise. Inbound handling, writes and close now all run on the one thread.
Reuses the existing SAL::MSocketQueueManager Post/IsOnQueueThread hooks; no ABI/layout change. Non-_SAL_TIME_H (asio) path unchanged — its io_service strand already serializes.
Change-Id: Ie3a8260714ca008fc810436b10f8b9d325c5b3b1