Skip to content

[core] Removed unnecessary post-cleaning of closed socket in the cleanup.#3327

Open
ethouris wants to merge 7 commits into
Haivision:masterfrom
ethouris:dev-fix-garbage-sockets
Open

[core] Removed unnecessary post-cleaning of closed socket in the cleanup.#3327
ethouris wants to merge 7 commits into
Haivision:masterfrom
ethouris:dev-fix-garbage-sockets

Conversation

@ethouris
Copy link
Copy Markdown
Collaborator

@ethouris ethouris commented May 22, 2026

The problem:

After the proper cleanup has been added to handle the fork case, the cleanup function, which also executes from the global destructor, does a usual socket cleanup, which was so far done only inside the GC thread, and it doesn't remove a socket that is still in the CRcvUList because that's a marker that the CRcvQueue::worker thread is still using it. In case when in a single snapshot of the library state all threads suddenly disappear - which may happen under certain circumstances - the cleanup function catches a situation of a stuck socket, for which there's no one left to free it.

We state that as long as the GC thread is running, it takes care of all sockets. When it is asked to quit by the stopGarbageCollector() call, it should completely close and delete all sockets. The closeAllSockets() then is run only "just in case", but in this situation it won't work properly if there are any sockets left that somehow the GC thread didn't delete.

Solution:

The post-cleanup of the sockets has been removed. For SRT library it is believed that if the GC thread has been joined, all sockets have been deleted and there's no need to do any post-checks here. If anything is still not cleaned up at that point, it simply means that there is some data corruption caused by the misuse of the library rules, so any kind of action would end up with even worse kind of undefined behavior - hence it's best and safest to do nothing in this situation.

There's also more explanations added in the documentation to the necessary call to srt_cleanup() and the cleanup facility done in the global destructor.

@ethouris ethouris added this to the v1.5.6 milestone May 22, 2026
@ethouris ethouris added Type: Maintenance Work required to maintain or clean up the code [core] Area: Changes in SRT library core labels May 22, 2026
Comment thread srtcore/api.cpp Fixed
Comment thread srtcore/api.cpp Fixed
Comment thread srtcore/queue.cpp Fixed
Mikolaj Malecki added 2 commits June 2, 2026 12:25
…moved cleaning up sockets after GC exit. Added description
@ethouris ethouris changed the title [core] Added death-garbage-aware cleanup [core] Removed unnecessary post-cleaning of closed socket in the cleanup. Jun 2, 2026
Copy link
Copy Markdown
Collaborator

@stevomatthews stevomatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[core] Area: Changes in SRT library core Type: Maintenance Work required to maintain or clean up the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants