alanxz / rabbitmq-c

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

Timeout or socket error when open socket no block #483

Open pipetus opened 6 years ago

pipetus commented 6 years ago

Hi,

I'm running rabbitmq-c v0.8.0 on an OpenWRT (ar71xx), in a device acting as a client in a LAN. The same system seems to behave differently behind different routers.

The problems I'm seeing are (this is part of my code):

    _socket  = amqp_tcp_socket_new( _connection );

    if( _socket == NULL )
    {
        log_error( "connect(): can't create a new socket");
        return false;
    }

    status = amqp_socket_open_noblock( _socket, _host.c_str(), _port, &_openTimeOut);

    if( status  !=  AMQP_STATUS_OK  )
    {
        log_error( "connect(): can't open socket: %d", status);
        return false;
    }

and here, not sure depending on what, the error returned is either -13 o -9. After digging into rabbitmq-c code, I understand these two return codes mainly rely on either poll() or connect() calls, but I cannot see which of the possible cases could be happening here.

On the other hand, as I mentioned, this happens behind two different routers; in one of them (the successfull one), I see that after the DNS queries to get the host ip the server has, a the client sends TCP SYN and ACK'ed by the server, whilst in the other, the client sends SYN, server ACKs and client sends RST right after, which could mean it indicates it's closing the connection.

I'd like to understand in which cases a rabbitmq client could be issueing a RST to the server.

Thanks, JP

alanxz commented 6 years ago

-13 = AMQP_STATUS_TIMEOUT - this means that rabbitmq-c was unable to resolve the hostname and open a connection before the specified timeout.

-9 = AMQP_STATUS_SOCKET_ERROR - this means that the library had an issue handling a socket. It may worth looking at errno after getting this back. strace may also be helpful in narrowing down which socket call is failing.

sa791017 commented 1 month ago

In this function status = amqp_socket_open_noblock( _socket, _host.c_str(), _port, &_openTimeOut);

Can i use DNS instead of ip address?