Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ConcoreJavaRuntimeCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ private class ZeroMQPort {
ZeroMQPort(String portType, String address, int socketType) {
ZMQ.Context ctx = getZmqContext();
this.socket = ctx.socket(socketType);
if (socketType == ZMQ.REQ) {
this.socket.setReqRelaxed(true);
this.socket.setReqCorrelate(true);
}
this.socket.setReceiveTimeOut(2000);
this.socket.setSendTimeOut(2000);
this.socket.setLinger(0);
Expand Down Expand Up @@ -771,4 +775,4 @@ Object parseKeyword() {
}
}
}
}
}
30 changes: 30 additions & 0 deletions TestConcoredockerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import org.zeromq.ZMQ;
import org.zeromq.ZMQException;

/**
* Tests for concoredocker read(), write(), unchanged(), initVal()
Expand Down Expand Up @@ -29,6 +31,7 @@ public static void main(String[] args) {
testReadParseError();
testReadTraversalBlocked();
testWriteTraversalBlocked();
testReqCanSendAfterMissingReply();

System.out.println("\n=== Results: " + passed + " passed, " + failed + " failed out of " + (passed + failed) + " tests ===");
if (failed > 0) {
Expand Down Expand Up @@ -251,4 +254,31 @@ static void testWriteTraversalBlocked() {
concoredocker.write(1, "../escape", Collections.singletonList((Object) 1.0), 0);
check("write traversal blocked: no escaped file", false, Files.exists(tmp.resolve("escape")));
}

static void testReqCanSendAfterMissingReply() {
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket peer = context.socket(ZMQ.REP);
peer.setReceiveTimeOut(2000);
peer.setLinger(0);
int port = peer.bindToRandomPort("tcp://127.0.0.1");

concoredocker.terminateZmq();
try {
concoredocker.initZmqPort("request", "connect", "tcp://127.0.0.1:" + port, "REQ");
concoredocker.write("request", "signal", Collections.singletonList((Object) 1.0), 0);
check("REQ peer receives first request", true, peer.recvStr() != null);

boolean secondWriteSucceeded = true;
try {
concoredocker.write("request", "signal", Collections.singletonList((Object) 2.0), 0);
} catch (ZMQException e) {
secondWriteSucceeded = false;
}
check("REQ can send again when reply is missing", true, secondWriteSucceeded);
} finally {
concoredocker.terminateZmq();
peer.close();
context.term();
}
}
}
Loading