[zeromq-dev] Memory hog from pipe.cpp

Francis Le Bourse zno-reply-francis.lebourse at sfr-sh.fr
Thu Dec 11 16:07:15 CET 2014


I have hit an issue similar to the one described in 
https://github.com/zeromq/libzmq/issues/1256, with a very high  
occurrence rate.
The server is a router, the clients connect via an ipc endpoint and go 
away almost immediately. The pipe is not destroyed and the server can 
"loose" several megabytes per minute.
Nothing appears with tools like valgrind/memcheck, valgrind/dhat because 
the memory is freed by the reaper when the server terminates so no leak 
is reported.

With the attached patch, the server's resident size remains stable, and 
doesn't seem to break anything else.
In case anyone is interested, I can provide the same patch but for 

Any feedback would be appreciated.

-------------- next part --------------
diff -urwBE libzmq-original/src/pipe.cpp libzmq/src/pipe.cpp
--- libzmq-original/src/pipe.cpp	2014-11-25 11:01:35.716930420 +0100
+++ libzmq/src/pipe.cpp	2014-12-11 15:39:16.826863495 +0100
@@ -279,20 +279,15 @@
             ||  state == delimiter_received
             ||  state == term_req_sent1);
-    //  This is the simple case of peer-induced termination. If there are no
-    //  more pending messages to read, or if the pipe was configured to drop
-    //  pending messages, we can move directly to the term_ack_sent state.
-    //  Otherwise we'll hang up in waiting_for_delimiter state till all
-    //  pending messages are read.
+    //  This is the simple case of peer-induced termination.
+    //  Always go to the term_ack_sent state because there will be no
+    //  other event and the memory (12 kb) will remain in use until
+    //  the reaper destroys the pipe.
     if (state == active) {
-        if (delay)
-            state = waiting_for_delimiter;
-        else {
             state = term_ack_sent;
             outpipe = NULL;
             send_pipe_term_ack (peer);
-    }
     //  Delimiter happened to arrive before the term command. Now we have the
     //  term command as well, so we can move straight to term_ack_sent state.
@@ -381,8 +376,10 @@
     //  There are still pending messages available, but the user calls
     //  'terminate'. We can act as if all the pending messages were read.
+    //  Same as in process_pipe_term, there will be no other event so
+    //  the memory will remain in use until te reaper claims it.
-    if (state == waiting_for_delimiter && !delay) {
+    if (state == waiting_for_delimiter) {
         outpipe = NULL;
         send_pipe_term_ack (peer);
         state = term_ack_sent;

More information about the zeromq-dev mailing list