|
20 | 20 | import java.io.IOException; |
21 | 21 | import java.net.InetAddress; |
22 | 22 | import java.net.SocketException; |
| 23 | +import java.net.SocketTimeoutException; |
23 | 24 | import java.util.Collections; |
24 | 25 | import java.util.HashMap; |
25 | 26 | import java.util.Map; |
@@ -108,6 +109,9 @@ public static final Map<String, Object> defaultClientProperties() { |
108 | 109 | /** Flag indicating whether the client received Connection.Close message from the broker */ |
109 | 110 | private volatile boolean _brokerInitiatedShutdown; |
110 | 111 |
|
| 112 | + /** Flag indicating we are still negotiating the connection in start */ |
| 113 | + private volatile boolean _inConnectionNegotiation; |
| 114 | + |
111 | 115 | /** Manages heart-beat sending for this connection */ |
112 | 116 | private final HeartbeatSender _heartbeatSender; |
113 | 117 |
|
@@ -248,6 +252,8 @@ public AMQConnection(String username, |
248 | 252 |
|
249 | 253 | this._heartbeatSender = new HeartbeatSender(frameHandler); |
250 | 254 | this._brokerInitiatedShutdown = false; |
| 255 | + |
| 256 | + this._inConnectionNegotiation = true; // we start out waiting for the first protocol response |
251 | 257 | } |
252 | 258 |
|
253 | 259 | /** |
@@ -385,6 +391,9 @@ public void start() |
385 | 391 | throw AMQChannel.wrap(sse); |
386 | 392 | } |
387 | 393 |
|
| 394 | + // We can now respond to errors having finished tailoring the connection |
| 395 | + this._inConnectionNegotiation = false; |
| 396 | + |
388 | 397 | return; |
389 | 398 | } |
390 | 399 |
|
@@ -538,7 +547,11 @@ private class MainLoop extends Thread { |
538 | 547 | * Called when a frame-read operation times out |
539 | 548 | * @throws MissedHeartbeatException if heart-beats have been missed |
540 | 549 | */ |
541 | | - private void handleSocketTimeout() throws MissedHeartbeatException { |
| 550 | + private void handleSocketTimeout() throws SocketTimeoutException { |
| 551 | + if (_inConnectionNegotiation) { |
| 552 | + throw new SocketTimeoutException("Timeout during Connection negotiation"); |
| 553 | + } |
| 554 | + |
542 | 555 | if (_heartbeat == 0) { // No heart-beating |
543 | 556 | return; |
544 | 557 | } |
|
0 commit comments