core: fix fd memory leak in reactor_proc_add_fd, causing crash due to memory extinguish and too many open files#3830
Open
danielzt wants to merge 1 commit intoOpenSIPS:masterfrom
Open
Conversation
…n files rtpproxy: Fix in timeout scenarios, leading crash due to memory leak and too many open files
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
rtpproxy: fix crash in timeout scenarios caused by file descriptor and memory leak, eventually leading to "Too many open files" errors and opensips crash.
Details
Under high load or unstable RTPProxy communication scenarios, OpenSIPS may trigger timeout conditions while handling RTPProxy sessions. In these cases, certain execution paths were not properly releasing allocated resources.
Specifically, when timeout or failure conditions occurred during RTPProxy interaction, associated file descriptors and memory structures were not consistently cleaned up. Over time, this resulted in:
gradual file descriptor exhaustion (EMFILE / "Too many open files")
lsof -p 2378548 | awk '{print $5}' | sort | uniq -c | sort -nr
818 sock
132 FIFO
68 unix
eventual crashes or service degradation
a lot of logs generated, leading to full disk usage
/sbin/opensips[2378548]: ERROR:rtpproxy:rtpproxy_io_new_callback: socket accept failed: Too many open files(24)
increasing memory usage
/sbin/opensips[2488108]: ERROR:core:fm_malloc: not enough free pkg memory (0 bytes left, need 16), please increase the "-M" command line parameter!
/sbin/opensips[2488108]: ERROR:core:reactor_proc_add_fd: failed to allocate a reactor_proc callback
The issue is generic and not tied to a specific SIP endpoint or UAC implementation. It becomes visible mainly in high CPS environments or deployments where RTPProxy instances become temporarily unreachable or slow to respond.
This behavior was reproduced in production under sustained traffic and confirmed via monitoring tools (
lsof, FD counters and memory observation).Solution
The patch ensures proper cleanup of resources in all timeout and error execution paths inside the rtpproxy handling logic.
Main changes include:
The fix does not alter normal RTPProxy operation logic; it only corrects incomplete cleanup during exceptional flows.
Stress testing confirmed that file descriptor usage remains stable over long-running sessions after applying the patch.
Compatibility
This change is fully backward compatible:
The patch only affects internal resource management during error handling.
Closing issues
N/A