Errors when rapidly opening/closing sockets and contexts
See original GitHub issueI’m attempting to create an instance of my ZMQ stack for each unit test in my test suite. But I get problems when I rapidly open/close sockets and contexts.
Some times I get this:
Exception in thread "reaper-1" java.lang.AssertionError
at zmq.Mailbox.recv(Mailbox.java:114)
at zmq.SocketBase.process_commands(SocketBase.java:830)
at zmq.SocketBase.in_event(SocketBase.java:927)
at zmq.Poller.run(Poller.java:237)
at java.lang.Thread.run(Thread.java:745)
Other times it hangs silently at ctx.term();
I’ve created a maven project with a single junit test that demonstrates the issue: https://github.com/augustl/jeromq-issue
For the record, the test case is:
public class ExampleText {
@Test
public void demonstrateIssue() {
for (int i = 0; i < 50; i++) {
performTest();
}
}
private void performTest() {
Context ctx = ZMQ.context(1);
Socket recvMsgSock = ctx.socket(ZMQ.PULL);
recvMsgSock.bind("tcp://*:5115");
Socket processMsgSock = ctx.socket(ZMQ.PUSH);
processMsgSock.bind("inproc://process-msg");
List<Socket> workerSocks = new ArrayList<Socket>();
for (int i = 0; i < 5; i++) {
Socket workerSock = ctx.socket(ZMQ.PULL);
workerSock.connect("inproc://process-msg");
workerSocks.add(workerSock);
}
Thread proxyThr = new Thread(new ZMQQueue(ctx, recvMsgSock, processMsgSock));
proxyThr.setName("Proxy thr");
proxyThr.start();
for (final Socket workerSock : workerSocks) {
Thread workerThr = new Thread(new Runnable() {
@Override
public void run() {
try {
while (true) {
byte[] msg = workerSock.recv();
// Process the msg!
}
} catch (Exception e) {
}
}
});
workerThr.setName("A worker thread");
workerThr.start();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("Closing now");
recvMsgSock.close();
processMsgSock.close();
for (Socket workerSock : workerSocks) {
workerSock.close();
}
ctx.term();
System.out.println("Successfully closed");
}
}
Issue Analytics
- State:
- Created 9 years ago
- Reactions:2
- Comments:12 (7 by maintainers)
Top Results From Across the Web
How to deal with java.net.SocketException: Broken pipe ...
A broken pipe error is seen when the remote end of the connection is closed gracefully. Solution: This exception usually arises when the...
Read more >websocket closing connection automatically - Stack Overflow
The solution is to listen to onclose events on the web socket client and when they occur, set a client side timeout to...
Read more >Chapter 2 - Sockets and Patterns - ZeroMQ Guide
It handles socket errors. It does all I/O in background threads. It uses lock-free techniques for talking between nodes, so there are never...
Read more >Sockets and Client/Server Communication
A socket is an endpoint of a connection between two processes. ... IOException - if an I/O error occurs when opening the socket....
Read more >How to Handle the Socket Exception in Java - Rollbar
Errors in code - A SocketException can also occur because of issues or bugs in code. For example, if a client sends a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just tried un-ignoring the test case again and it’s still hanging, so this is still an issue.
It would probably be worth examining what, exactly, we’re doing in our test suite to get it to pass consistently! (I’m not trying to be snarky, just a thought that just occurred to me.)
Any update on this ? It is really a problem for CI.