RabbitMQ-C : What happens if we destroy the connection without closing the channel before?

352 views
Skip to first unread message

Rodrigo Pimenta Carvalho

unread,
Dec 2, 2014, 12:50:45 PM12/2/14
to rabbitm...@googlegroups.com


Dear RabbitMQ-C users:

My client is a producer and it is producing messages to the queue in the broker, very well.

Let's suppose my C code execute a "amqp_destroy_connection(........);" without doing a " amqp_channel_close(......);" before.
What will happen in this case? That is, will some problem rises in my client? Is my client going to unstable?

Any hint will be very helpful!

Best regards.


RODRIGO PIMENTA CARVALHO
Inatel Competence Center
Software
Ph: +55 35 3471 9300 (Brasil)

Alan Antonuk

unread,
Dec 4, 2014, 12:00:33 AM12/4/14
to Rodrigo Pimenta Carvalho, rabbitm...@googlegroups.com
You do not need to close channels when closing the connection, they will be closed implicitly as a part of the connection shutdown.

If possible call amqp_connection_close() before calling amqp_destroy_connection().  The former sends a shutdown message to the broker (though its not required and will not destabilize things on the client side). If you are already in an errored state, you can call amqp_destroy_connection(), as further communication with the broker will cause further errors.

-Alan

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send an email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alan Antonuk

unread,
Dec 22, 2014, 5:17:08 PM12/22/14
to Rodrigo Pimenta Carvalho, rabbitm...@googlegroups.com
Please keep it on-list.

-Alan

On Thu, Dec 4, 2014 at 3:31 AM, Rodrigo Pimenta Carvalho <pim...@inatel.br> wrote:
Hi Alan.

Thank you very much.

My difficulty is to know exactly when I should and when I shouldn't call amqp_connection_close(). If I make a mistake, I get a segmentation fault.

If you've successfully created a socket, this should not happen. I'm interested in hearing how you got it to segfault.
 

You said: "If possible call amqp_connection_close()...". But, how to know for sure if it is possible? I have noticed that there are erroneous situations when it is possible to call amqp_connection_close(), and others when it is not. But I don't know which is which.

If you've successfully created a amqp_socket_t, then amqp_connection_close() should not segfault (Unless you get AMQP_STATUS_NO_MEMORY in which case you've run out of memory and you're in an undefined state - likely your whole program is in a undefined state at this point. Your best option might be to crash, or exit quickly).

You should also look at the comments in amqp.h, as this should give you some guidance on how to handle errors.


For example, for the following erroneous cases bellow, when is it possible and when isn't it possible to call amqp_connection_close() before rebuild the connection?


                case AMQP_STATUS_NO_MEMORY:

                case AMQP_STATUS_HOSTNAME_RESOLUTION_FAILED:
                case AMQP_STATUS_CONNECTION_CLOSED:

                case AMQP_STATUS_BAD_URL:

                case AMQP_STATUS_SOCKET_ERROR:

                case AMQP_STATUS_INVALID_PARAMETER:

                case AMQP_STATUS_TIMEOUT:

                case AMQP_STATUS_HEARTBEAT_TIMEOUT:

                case  AMQP_STATUS_TCP_ERROR:

                case  AMQP_STATUS_TCP_SOCKETLIB_INIT_ERROR:

                case AMQP_STATUS_SSL_HOSTNAME_VERIFY_FAILED :

                case AMQP_STATUS_SSL_PEER_VERIFY_FAILED:

                case  AMQP_STATUS_SSL_CONNECTION_FAILED:


By the way, I have also noticed that calling amqp_destroy_connection() immediately after getting case AMQP_STATUS_UNEXPECTED_STATE or case AMQP_STATUS_SSL_ERROR cause problems in the client (segmentation fault, for example).
For cases AMQP_STATUS_UNEXPECTED_STATE and AMQP_STATUS_SSL_ERROR, how to free the memory used by the amqp_connection_state_t, before trying to rebuild the connection?

Its possible that these are bugs. If you could be more specific which function returns these and provide a small example I can better help you. 

Best regards.

Rodrigo Pimenta Carvalho.












RODRIGO PIMENTA CARVALHO
Inatel Competence Center
Software
Ph: +55 35 3471 9300     (Brasil)
________________________________________
De: Alan Antonuk [alan.a...@gmail.com]
Enviado: quinta-feira, 4 de dezembro de 2014 3:00
Para: Rodrigo Pimenta Carvalho
Cc: rabbitm...@googlegroups.com
Assunto: Re: [rabbitmq-users] RabbitMQ-C : What happens if we destroy the connection without closing the channel before?


You do not need to close channels when closing the connection, they will be closed implicitly as a part of the connection shutdown.

If possible call amqp_connection_close() before calling amqp_destroy_connection().  The former sends a shutdown message to the broker (though its not required and will not destabilize things on the client side). If you are already in an errored state, you can call amqp_destroy_connection(), as further communication with the broker will cause further errors.

-Alan

On Tue, Dec 2, 2014 at 9:49 AM, Rodrigo Pimenta Carvalho <pim...@inatel.br<mailto:pim...@inatel.br>> wrote:


Dear RabbitMQ-C users:

My client is a producer and it is producing messages to the queue in the broker, very well.

Let's suppose my C code execute a "amqp_destroy_connection(........);" without doing a " amqp_channel_close(......);" before.
What will happen in this case? That is, will some problem rises in my client? Is my client going to unstable?

Any hint will be very helpful!

Best regards.


RODRIGO PIMENTA CARVALHO
Inatel Competence Center
Software
Ph: +55 35 3471 9300<tel:%2B55%2035%203471%209300>     (Brasil)


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com<mailto:rabbitmq-users%2Bunsu...@googlegroups.com>.
To post to this group, send an email to rabbitm...@googlegroups.com<mailto:rabbitm...@googlegroups.com>.

Rodrigo Pimenta Carvalho

unread,
Dec 23, 2014, 7:37:36 AM12/23/14
to Alan Antonuk, rabbitm...@googlegroups.com


Hi Alan.

Recently I have done a refectory in my code and I have not seen that issue, at least until now. But, I still have to execute lots of tests in my project across January.
So, if I find some issue, I will isolate the problem in a short peace of code and reproduce here.

Thanks for now.

Br,



RODRIGO PIMENTA CARVALHO
Inatel Competence Center
Software
Ph: +55 35 3471 9300 (Brasil)
________________________________________
De: Alan Antonuk [alan.a...@gmail.com]
Enviado: segunda-feira, 22 de dezembro de 2014 20:17
Para: Rodrigo Pimenta Carvalho; rabbitm...@googlegroups.com
Assunto: Re: [rabbitmq-users] RabbitMQ-C : What happens if we destroy the connection without closing the channel before?

Please keep it on-list.

-Alan

Ph: +55 35 3471 9300<tel:%2B55%2035%203471%209300> (Brasil)
________________________________________
De: Alan Antonuk [alan.a...@gmail.com<mailto:alan.a...@gmail.com>]
Enviado: quinta-feira, 4 de dezembro de 2014 3:00
Para: Rodrigo Pimenta Carvalho
Cc: rabbitm...@googlegroups.com<mailto:rabbitm...@googlegroups.com>
Assunto: Re: [rabbitmq-users] RabbitMQ-C : What happens if we destroy the connection without closing the channel before?

You do not need to close channels when closing the connection, they will be closed implicitly as a part of the connection shutdown.

If possible call amqp_connection_close() before calling amqp_destroy_connection(). The former sends a shutdown message to the broker (though its not required and will not destabilize things on the client side). If you are already in an errored state, you can call amqp_destroy_connection(), as further communication with the broker will cause further errors.

-Alan

On Tue, Dec 2, 2014 at 9:49 AM, Rodrigo Pimenta Carvalho <pim...@inatel.br<mailto:pim...@inatel.br><mailto:pim...@inatel.br<mailto:pim...@inatel.br>>> wrote:


Dear RabbitMQ-C users:

My client is a producer and it is producing messages to the queue in the broker, very well.

Let's suppose my C code execute a "amqp_destroy_connection(........);" without doing a " amqp_channel_close(......);" before.
What will happen in this case? That is, will some problem rises in my client? Is my client going to unstable?

Any hint will be very helpful!

Best regards.


RODRIGO PIMENTA CARVALHO
Inatel Competence Center
Software
Ph: +55 35 3471 9300<tel:%2B55%2035%203471%209300><tel:%2B55%2035%203471%209300> (Brasil)

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com<mailto:rabbitmq-users%2Bunsu...@googlegroups.com><mailto:rabbitmq-users%2Bunsu...@googlegroups.com<mailto:rabbitmq-users%252Buns...@googlegroups.com>>.
To post to this group, send an email to rabbitm...@googlegroups.com<mailto:rabbitm...@googlegroups.com><mailto:rabbitm...@googlegroups.com<mailto:rabbitm...@googlegroups.com>>.
Reply all
Reply to author
Forward
0 new messages