diff --git a/src/main/java/com/rabbitmq/client/impl/AMQConnection.java b/src/main/java/com/rabbitmq/client/impl/AMQConnection.java index dfaa8989e..6eb181c6a 100644 --- a/src/main/java/com/rabbitmq/client/impl/AMQConnection.java +++ b/src/main/java/com/rabbitmq/client/impl/AMQConnection.java @@ -321,6 +321,10 @@ public void start() // initiator) is to wait for a connection.start method to // arrive. _channel0.enqueueRpc(connStartBlocker); + // Must happen before the header is sent: sending it can make the broker reply + // immediately, and the I/O thread that reads that reply needs the connection + // reference to already be in place, or it hits a null reference. + this._frameHandler.initialize(this); try { // The following two lines are akin to AMQChannel's // transmit() method for this pseudo-RPC. @@ -331,8 +335,6 @@ public void start() throw ioe; } - this._frameHandler.initialize(this); - AMQP.Connection.Start connStart; AMQP.Connection.Tune connTune = null; try {