vcabbage / amqp

AMQP 1.0 client library for Go.
https://godoc.org/pack.ag/amqp
MIT License
134 stars 97 forks source link

amqp.ConnConnectTimeout not respected when target host unavailable #169

Closed lsattem closed 5 years ago

lsattem commented 5 years ago

It does not seem that the option amqp.ConnConnectTimeout works properly, or perhaps I'm just misunderstanding it. I connect to an ActiveMQ server via ssh tunnel. When the ssh tunnel is closed, and the server cannot be reached, I'd expect amqp to give up after 30 seconds with ConnConnectTimeout set to 30 seconds. However, it hangs for about 2 minutes before giving up and gives the following error message: connect: connection timed out

My code is as follows:

client, err = amqp.Dial("amqp://"+broker+"?transport.transformer=jms",
    amqp.ConnConnectTimeout(time.Second*30),
    amqp.ConnIdleTimeout(0),
    amqp.ConnSASLAnonymous(),
)

Sorry if there's already been an issue on this!

vcabbage commented 5 years ago

Thanks for pointing this out. The connect timeout is currently applied only after the TCP session is established. It should also be applied to the session setup.

Would you mind testing https://github.com/vcabbage/amqp/tree/issue169?

lsattem commented 5 years ago

That works nicely! Now it drops the attempt after the specified time and gives "i/o timeout". Thanks for the quick response and fix :)

vcabbage commented 5 years ago

Great! Tagged as v0.12.2.