@@ -309,12 +309,13 @@ end
309
309
# Async message handler framework begin
310
310
# ----------------------------------------
311
311
function wait_for_state (c, states; interval= 1 , timeout= typemax (Int))
312
- t1 = time ()
313
- while ! (c. state in states)
314
- ((time () - t1) > timeout) && (return false )
315
- sleep (interval)
312
+ timedwait (Float64 (timeout); pollint= Float64 (interval)) do
313
+ # if we are looking for open states, and connection gets closed in the meantime, it's an error, break out
314
+ conn_error = ! (CONN_STATE_CLOSED in states) && (c. state == CONN_STATE_CLOSED)
315
+ state_found = (c. state in states)
316
+ conn_error || state_found
316
317
end
317
- true
318
+ c . state in states
318
319
end
319
320
320
321
function connection_processor (c, name, fn)
@@ -512,7 +513,11 @@ function channel(c::Connection, id::Integer, create::Bool; connect_timeout=DEFAU
512
513
send_channel_open (chan)
513
514
514
515
if ! wait_for_state (chan, CONN_STATE_OPEN; timeout= connect_timeout)
515
- throw (AMQPClientException (" Channel handshake failed" ))
516
+ error_message = " Channel handshake failed"
517
+ if nothing != = chan. closereason
518
+ error_message = string (error_message, " - " , string (chan. closereason. code), " (" , convert (String, chan. closereason. msg), " )" )
519
+ end
520
+ throw (AMQPClientException (error_message))
516
521
end
517
522
end
518
523
else
@@ -562,7 +567,11 @@ function connection(; virtualhost="/", host="localhost", port=AMQPClient.AMQP_DE
562
567
flush (AMQPClient. sock (chan))
563
568
564
569
if ! AMQPClient. wait_for_state (conn, AMQPClient. CONN_STATE_OPEN; timeout= connect_timeout) || ! AMQPClient. wait_for_state (chan, AMQPClient. CONN_STATE_OPEN; timeout= connect_timeout)
565
- throw (AMQPClientException (" Connection handshake failed" ))
570
+ error_message = " Connection handshake failed"
571
+ if nothing != = chan. closereason
572
+ error_message = string (error_message, " - " , string (chan. closereason. code), " (" , convert (String, chan. closereason. msg), " )" )
573
+ end
574
+ throw (AMQPClientException (error_message))
566
575
end
567
576
chan
568
577
end
0 commit comments