-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
intermittent memory leak for req/rep send/recv. #2602
Comments
Your program is both connecting and binding the same socket:
That's undefined behaviour - can you try to repro without that please? |
Yeah, that was a copypaste error from sending_thread() I overlooked, sorry. Corrected minimal case: valgrind output:
|
I can reproduce but like 1 out of 50 times, it will be a bit of a pain to narrow down (PRs welcome!) |
If I move zmq context operations to main() and pass ctx to threads ( zmq_recv_req_rep_v2.txt ), valgrind no longer reports any leaks (or at least it's less than 1 in 100 runs). Looks like zmq_ctx_{new,destroy}() shouldn't be used simultaneously in multiple threads. |
Using a single context for the life time of the application is recommended practice, yes. But it should still work fine - perhaps it's a linger issue. Could you please try setting ZMQ_LINGER to -1 on both sockets and try again? |
With linger set ( |
It's metadata, I wonder if it's related to #2567 |
|
Ok, thanks. To me this smells like a possible race condition at context shutdown - which means if you use the same context for the whole lifetime of your application it should not have an impact. I'll try and reproduce more and investigate, help is of course welcome. |
I've also managed to reproduce it. This is what I've got on second run (Ubuntu 14, same command line):
|
It seems that reference count of |
Definitely one
|
Sorry for close/reopen, wrong button... |
If you also add a call to zmq::print_backtrace (from err.hpp) you'll see where they are made (install and build with libunwind-dev) |
@bluca Great! I'll try that. Then we will find the missing one. |
I would recommend a small and simple fix. Doing sweeping refactoring across the core library is tricky and risky. |
This is the missing
Edit: actually reaper always receives |
So it is a race at shutdown. Does it still happen with linger at -1 ? |
Windows stack trace:
|
…Solution: memory leak fixed.
Found it!
When leak happens this condition is true and
I've made a PR for this. |
Problem: intermittent memory leak for req/rep send/recv. #2602 Solution: memory leak fixed.
Great stuff, thanks! @Matthew-Jemielity could you please pull and try again? Fixed by #2609 |
I confirm my tests no longer leak with the patch. Thank you! |
Hi,
While unit testing my project using zmq I found randomly occuring memory leak for a REQ/REP socket pair doing zmq_send{,_const} and zmq_recv. I'm attaching an almost-minimal self-contained program which reproduces this issue:
zmq_recv_req_rep.txt
Hopefully I'm using libzmq correctly.
There seems to be some kind of race condition involved, since checking with valgrind can have four different outcomes:
The errors seem easier to reproduce on 32-bit system.
ZMQ I'm using was compiled from source, commit 2d83acc , through
./autogen.sh && ./configure --prefix=/usr && make && make check && sudo make install
.Tested on systems:
4.2.0-42-lowlatency #49~14.04.1-Ubuntu SMP PREEMPT Wed Jun 29 21:21:58 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux, gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4, valgrind-3.10.1
4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:06:37 UTC 2016 i686 i686 i686 GNU/Linux, gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4, valgrind-3.10.1
Source was compiled with:
gcc -Wall -Wextra -std=c99 -pedantic zmq_recv_req_rep.c -lzmq -pthread -o test
and checked with:
valgrind --leak-check=full ./test
valigrind message:
Regards,
Matt
The text was updated successfully, but these errors were encountered: