alanxz / rabbitmq-c

RabbitMQ C client
MIT License
1.76k stars 669 forks source link

When closing MQ Connection getting "An unexpected method was received" error #821

Open vikirj opened 6 months ago

vikirj commented 6 months ago

When waiting for consuming message using amqp_consume_message(connection, &envelope, NULL, 0) function. if close the channel and connection without receiving any message ,

die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); die_on_error(amqp_destroy_connection(conn), "Ending connection");

it throws An unexpected method was received 1310761 or An unexpected method was received 655411 error some time. some times the connection gets closed successfully.

could you please let us know the 1310761 and 655411 this code meaning.

Note: using v0.11.0 version

alanxz commented 6 months ago

1310761 - is the channel.close method link

655411 - is the connection.close method link

vikirj commented 6 months ago

Thanks for the response.

When I close the channel ( 1310761 - code returns ). and I could not close the connection after.

(i.e)

if I call die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); then

amqp_consume_message(conn, &envelope, NULL, 0); - this message-consumption function exits.

(amqp_rpc_reply_t ret) its reply_type is AMQP_RESPONSE_LIBRARY_EXCEPTION and library_error AMQP_STATUS_SOCKET_ERROR (or) AMQP_STATUS_UNEXPECTED_STATE

log:

ret.reply_type : 2 ret.library_error : -9 (or) -16

when this error is received, I could not close and destroy the connection and the following 2 functions are NOT called:

die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); 
die_on_error(amqp_destroy_connection(conn), "Ending connection");

and the application still running.