Skip to content

[ON-1531] socket.io: serialize websocket writes onto the socket-queue…#8

Open
RichardStoff wants to merge 1 commit into
summittech-ca:masterfrom
RichardStoff:master
Open

[ON-1531] socket.io: serialize websocket writes onto the socket-queue…#8
RichardStoff wants to merge 1 commit into
summittech-ca:masterfrom
RichardStoff:master

Conversation

@RichardStoff

Copy link
Copy Markdown

… 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

… 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
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