Repository navigation
Process closed sockets pending destruction before polling in PollRawUDPSockets - #460
Open
siddiqueirshad wants to merge 1 commit into
Open
siddiqueirshad wants to merge 1 commit into
siddiqueirshad wants to merge 1 commit into
Conversation
…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.
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.
Summary
Fixes #458
When a socket is closed on another thread (or during rapid init/kill/close cycles),
CRawUDPSocketImpl::InternalAddToCleanupQueue()setsm_callback.m_fnCallback = nullptrto mark the socket as pending destruction, setss_bRawSocketPendingDestruction = true, and wakes the service thread.However, in the service thread loop,
PollRawUDPSockets()is invoked beforeProcessDeferredOperations()(which invokesProcessPendingDestroyClosedRawUDPSockets()). IfPollRawUDPSocketsruns while a socket is queued for cleanup, theDBGFLAG_ASSERTloop:trips because the closed socket is still present in
s_vecRawSocketswith a null callback.Solution
Call
ProcessPendingDestroyClosedRawUDPSockets()at the entry ofPollRawUDPSockets()before the sanity loop and befores_vecPollFDsis populated. Ifs_bRawSocketPendingDestructionis set, any closed sockets are promptly purged froms_vecRawSockets, ensuring they are not polled and preventing the assertion failure.