Crashes if binding TCP socket not to INADDR_ANY - Unix

This is a discussion on Crashes if binding TCP socket not to INADDR_ANY - Unix ; Hi TCP server suffers random crashes if server sockets were bound not to INADDR_ANY, but to one of multiple available NICs. Linux 2.6.16, AMD 64, SuSE 9.3. Binding code: struct sockaddr_in name; string hostname; // IP address supposed to be ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Crashes if binding TCP socket not to INADDR_ANY

  1. Crashes if binding TCP socket not to INADDR_ANY

    Hi

    TCP server suffers random crashes if server sockets were bound not to
    INADDR_ANY, but to one of multiple available NICs. Linux 2.6.16, AMD
    64, SuSE 9.3. Binding code:

    struct sockaddr_in name;
    string hostname; // IP address supposed to be here
    ....

    memset (&name, '\0', sizeof(name));

    if (!hostname.empty()) {
    if (inet_aton(hostname.c_str(), &name.sin_addr) <= 0) {
    WriteToLog(ERROR_MESSAGE, "TCP server::inet_aton: %m");
    abort();
    }
    } else {
    name.sin_addr.s_addr = htonl (INADDR_ANY);
    }

    name.sin_family = AF_INET;
    name.sin_port = htons (port);

    if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0) {
    WriteToLog(ERROR_MESSAGE, "TCP server::bind: %m");
    abort();
    }


    We've also tried gethostbyname() instead of inet_aton(). bind()
    returns OK, but then, after 3-5 minutes of accepting TCP connections,
    server crashes. No segfault information is left in syslog.

    Any ideas appreciated, thanks.

    Regards,
    Alex


  2. Re: Crashes if binding TCP socket not to INADDR_ANY

    On 4 Apr, 08:12, "Alex" wrote:

    > TCP server suffers random crashes if server sockets were bound not to
    > INADDR_ANY, but to one of multiple available NICs. Linux 2.6.16, AMD
    > 64, SuSE 9.3. Binding code:


    []

    > We've also tried gethostbyname() instead of inet_aton(). bind()
    > returns OK,


    As bind() succeeds, it does not seem to be a problem caused by address
    manipulation routines.

    > but then, after 3-5 minutes of accepting TCP connections,
    > server crashes. No segfault information is left in syslog.
    >
    > Any ideas appreciated, thanks.


    Running it under strace, or better, valgrind might provide wealth of
    information.


  3. Re: Crashes if binding TCP socket not to INADDR_ANY

    Hi Maxim,

    On 4 Сав, 10:26, "Maxim Yegorushkin"
    wrote:

    >
    > > but then, after 3-5 minutes of accepting TCP connections,
    > > server crashes. No segfault information is left in syslog.

    >
    > > Any ideas appreciated, thanks.

    >
    > Running it under strace, or better, valgrind might provide wealth of
    > information.


    strace shows the following:

    10:44:42.063352 select(12, [11], NULL, NULL, {0,
    17861364035700674548}) = 0 (Timeout)
    10:44:42.063411 select(13, [11 12], NULL, NULL, {1800, 0}) = ?
    ERESTARTSYS (To be restarted)
    ) = -1 EINTR (Interrupted system call)
    ) = ? ERESTARTSYS (To be restarted)
    ) = ? ERESTARTNOHAND (To be restarted)
    ) = ? ERESTARTNOHAND (To be restarted)
    ) = ? ERESTARTNOHAND (To be restarted)
    ) = ? ERESTARTNOHAND (To be restarted)
    10:45:01.554096 +++ killed by SIGKILL +++

    I thought ERESTARTSYS should never reach userspace? Hmm. Could that be
    a HW/driver problem?

    Regards,
    Alex


  4. Re: Crashes if binding TCP socket not to INADDR_ANY

    Hi

    The problem is solved. I'm so sorry, the bug was actually in another
    place. As it can be [now] clearly seen from the strace log, the server
    gets killed by other process. In this case, by the misconfigured
    watchdog

    Alex



+ Reply to Thread