JustinTulloss/zeromq.node — pull request #248 by utvara (2013-10-30 08:11:26+00:00)
Title: handle received message immediately for receive only sockets to prevent memory leak in driver

The problem:

We have an active upstream (PUSH) that will accumulate hundreds of thousands of messages while downstream (PULL) is disconnected. Once downstream nodes become available due to previous implementation we see a huge memory pile up.

Ratio behind the problem is that messages from socket are drained with while loop and message processing is postponed with setImmediate. By the time event loop is able to skip a beat all inbound zmq messages are piled up in this closure:

```
(function(emitArgs) {
setImmediate(function(){
self.emit.apply(self, emitArgs);
});
})(emitArgs);
```

Proposed solution is changing only the behaviour of unidirectional receive only sockets by not allowing the messages to be piled up in closures.

I'm not sure of the original intent of setImmediate so I did not remove it completely for other socket types.