Skip to content

Commit

Permalink
throw exception when no response received after timeout, fix the zmqS…
Browse files Browse the repository at this point in the history
…ocket.send/recv exception handling

Signed-off-by: Leo Ma <[email protected]>
  • Loading branch information
leomaatEric committed Dec 10, 2020
1 parent 66b139b commit 732a357
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/cisco/trex/stateless/TRexTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,21 @@ public synchronized String sendJson(String json) {

byte[] compressed = this.dataCompressor.compressStringToBytes(json);

String response;
try {
zmqSocket.send(compressed);
byte[] msg = zmqSocket.recv();
response = this.dataCompressor.decompressBytesToString(msg);
} catch (ZMQException e) {
throw new IllegalStateException(
"Did not get any response from server "
+ getHost()
+ " within timeout "
+ zmqSocket.getReceiveTimeOut(),
"Failed to send or recv json request or response due to ZMQ error: " + e.getErrorCode(),
e);
}
byte[] msg = zmqSocket.recv();

String response = this.dataCompressor.decompressBytesToString(msg);
if (response == null) {
throw new IllegalStateException(
"Got null json response, the reason could be get no response from server within timeout, or the ZMQ socket connection is in bad state either on client side or on server side.");
}
LOGGER.debug("JSON Resp: {}", response);
return response;
}
Expand Down

0 comments on commit 732a357

Please sign in to comment.