Service: BSD: Fix race condition between socket closure and packet reception #96

Merged
Collecting merged 3 commits from fix/bsd-socket into main 2026-01-14 14:38:46 -05:00
Collaborator

This change introduces a mutex to synchronize access to the file descriptor table within the BSD service. Previously, a data race existed between the Network thread (distributing incoming packets) and the IPC thread (cleaning up or resetting sockets during closure).

When backing out of a multiplayer lobby or when a communication error occured in certain titles, the game would frequently close sockets while packets were still being processed. Without synchronization, the network thread could attempt to access a socket pointer at the same moment it was being reset, leading to corrupted state and guest-side null pointer dereferences (PC=0).

Additionally, ProxySocket::Close now flushes its internal packet queue to ensure no stale data is processed for a closed descriptor, and the destruction logic in CloseImpl is now atomic relative to the packet reception loop.

This change introduces a mutex to synchronize access to the file descriptor table within the BSD service. Previously, a data race existed between the Network thread (distributing incoming packets) and the IPC thread (cleaning up or resetting sockets during closure). When backing out of a multiplayer lobby or when a communication error occured in certain titles, the game would frequently close sockets while packets were still being processed. Without synchronization, the network thread could attempt to access a socket pointer at the same moment it was being reset, leading to corrupted state and guest-side null pointer dereferences (PC=0). Additionally, ProxySocket::Close now flushes its internal packet queue to ensure no stale data is processed for a closed descriptor, and the destruction logic in CloseImpl is now atomic relative to the packet reception loop.
Collecting deleted branch fix/bsd-socket 2026-01-14 14:38:46 -05:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Kintoki/Emulator!96
No description provided.