From 732a357f6e6bbc0a33d51f80bdc5d2aa70bcddc6 Mon Sep 17 00:00:00 2001 From: Leo Ma Date: Thu, 10 Dec 2020 16:56:13 +0800 Subject: [PATCH] throw exception when no response received after timeout, fix the zmqSocket.send/recv exception handling Signed-off-by: Leo Ma --- .../com/cisco/trex/stateless/TRexTransport.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/cisco/trex/stateless/TRexTransport.java b/src/main/java/com/cisco/trex/stateless/TRexTransport.java index 25c0e29..58e9c11 100644 --- a/src/main/java/com/cisco/trex/stateless/TRexTransport.java +++ b/src/main/java/com/cisco/trex/stateless/TRexTransport.java @@ -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; }