Skip to content

Process closed sockets pending destruction before polling in PollRawUDPSockets - #460

Open
siddiqueirshad wants to merge 1 commit into
ValveSoftware:masterfrom
siddiqueirshad:fix/raw-socket-pending-destruction-assert
Open

siddiqueirshad wants to merge 1 commit into
ValveSoftware:masterfrom
siddiqueirshad:fix/raw-socket-pending-destruction-assert

Conversation

@siddiqueirshad

Copy link
Copy Markdown

Summary

Fixes #458

When a socket is closed on another thread (or during rapid init/kill/close cycles), CRawUDPSocketImpl::InternalAddToCleanupQueue() sets m_callback.m_fnCallback = nullptr to mark the socket as pending destruction, sets s_bRawSocketPendingDestruction = true, and wakes the service thread.

However, in the service thread loop, PollRawUDPSockets() is invoked before ProcessDeferredOperations() (which invokes ProcessPendingDestroyClosedRawUDPSockets()). If PollRawUDPSockets runs while a socket is queued for cleanup, the DBGFLAG_ASSERT loop:

for ( CRawUDPSocketImpl *pSock: s_vecRawSockets )
{
    Assert( pSock->m_callback.m_fnCallback );
}

trips because the closed socket is still present in s_vecRawSockets with a null callback.

Solution

Call ProcessPendingDestroyClosedRawUDPSockets() at the entry of PollRawUDPSockets() before the sanity loop and before s_vecPollFDs is populated. If s_bRawSocketPendingDestruction is set, any closed sockets are promptly purged from s_vecRawSockets, ensuring they are not polled and preventing the assertion failure.

…DPSockets (ValveSoftware#458)

When a socket is closed on another thread, InternalAddToCleanupQueue sets
m_callback.m_fnCallback = nullptr to mark it pending destruction and wakes
the service thread. If PollRawUDPSockets runs before ProcessDeferredOperations
has executed ProcessPendingDestroyClosedRawUDPSockets, the DBGFLAG_ASSERT
sanity loop trips on pSock->m_callback.m_fnCallback.

Calling ProcessPendingDestroyClosedRawUDPSockets at the start of PollRawUDPSockets
ensures closed sockets are destroyed and removed from s_vecRawSockets before
the sanity check and before polling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant