Skip to content

Commit 732a357

Browse files
committed
throw exception when no response received after timeout, fix the zmqSocket.send/recv exception handling
Signed-off-by: Leo Ma <[email protected]>
1 parent 66b139b commit 732a357

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main/java/com/cisco/trex/stateless/TRexTransport.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,21 @@ public synchronized String sendJson(String json) {
135135

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

138+
String response;
138139
try {
139140
zmqSocket.send(compressed);
141+
byte[] msg = zmqSocket.recv();
142+
response = this.dataCompressor.decompressBytesToString(msg);
140143
} catch (ZMQException e) {
141144
throw new IllegalStateException(
142-
"Did not get any response from server "
143-
+ getHost()
144-
+ " within timeout "
145-
+ zmqSocket.getReceiveTimeOut(),
145+
"Failed to send or recv json request or response due to ZMQ error: " + e.getErrorCode(),
146146
e);
147147
}
148-
byte[] msg = zmqSocket.recv();
149148

150-
String response = this.dataCompressor.decompressBytesToString(msg);
149+
if (response == null) {
150+
throw new IllegalStateException(
151+
"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.");
152+
}
151153
LOGGER.debug("JSON Resp: {}", response);
152154
return response;
153155
}

0 commit comments

Comments
 (0)