This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Why does HTTPCli_connect sometimes encounter EAI_BADFLAGS?

I'm using TIRTOS 2.16.00.08 on a TM4C1294 chip.

I have 2 HTTPS tasks that run and I am occasionally seeing (once or twice every few days) an error on when I run "HTTPCli_connect()".

The http error code is (-102) HTTPCli_ECONNECTFAIL.
The socket level error code from HTTPCli_getSocketError() is (-1) EAI_BADFLAGS. I think this is defined in serrno.h right?

The behavior of the error is that sometimes (once a day or even less) for 1-2 minutes HTTPCli_Connect() will return this error.
After a short time, it will start working again and not return any error code.

I currently resolve the DNS once and reuse it multiple times!


Do I need to resolve the HTTP server (using getaddrinfo) on every HTTP request?
Is that the cause of my problem (most likely)?

Thanks for the help,
Subhash

  • It seems to me that if the DNS IP address changed it wouldn't start working again after a short time. Can you use wireshark to monitor the traffic between your board and the server? You may have to apply some strategic filters to reduce the amount of packets captured. Is your device engaging in IP traffic often enough to keep the router aware of your presence?

    Alan
  • I'll try and setup wireshark but I currently don't have the tools to easily do that.

    The device engages in HTTP traffic every 30-60 seconds. It's essentially providing a monitoring service that notifies someone if the device isn't heard from for 2 minutes.

    Are you saying that this error is a network error? I don't really know what EAI_BADFLAGS means. Does that mean the socket being established tried to connect to the server and failed with that error? I need to try and trace through the source code to understand what would trigger EAI_BADFLAGS. Are there any registers that I should look at when this happens?

    Thank you for the help.
  • I'm now running a wireshark capture and will report if I can capture at the time the error happens. It happens quite infrequently so that might be difficult or take quite some time.


    Meanwhile, I have change my HTTPS tasks to resolve the DNS on every single HTTP request. Each task has it's own addrinfo struct to store it's results.

    What I have seen so far is that sometimes, I will see getaddrinfo return -2. This looks like a EAI_NONAME failure now. However, it looks like it's the exact same behavior as the HTTP_Connect socket error. It happens for about 1-2 minutes very infrequently and resolves itself without any changes. Is there a typical reason that one would see EAI_NONAME failures that occur only sometimes?

    For reference, this is my DNS resolution function:

    void ResolveDomain() {
    
        // Variables used for hostname resolution.
        int ret;
        struct addrinfo hints;
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = AF_INET;
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_protocol = IPPROTO_TCP;
    
     
            if (DomainResolvedFlag) {
                freeaddrinfo(DNS_Results);
                PrintDebug("Freed addrinfo -- Re-resolving Domain.");
            }
    
            ret = getaddrinfo(HOSTNAME, PORT, &hints, &DNS_Results_Post);
    
            if (ret != 0) {
                PrintError(ret, "ResolveDomain(): getaddrinfo() failed!");
                DomainResolvedFlag = false;
            } else {
                PrintDebug("Resolved Domain.");
                DomainResolvedFlag = true;
            }
    
    }

  • I'm not aware of a standard reason for the EAI_NONAME error but the thread below indicates that this does occur occasionally on some platforms:

    e2e.ti.com/.../554045

    Alan
  • Sorry I'm a little confused. The thread you linked looks like a timing/ssl issue? I'm not sure how that is similar to my very rare dns related issue?

  • Oops. I've been having trouble with e2e not posting my replies after I press "post". When I came back to try again, my copy/paste buffer was no longer current and I pasted the wrong link.


    Trying again:

    Alan
      

  • Hmm, do you think it could be related? It looks like for their case, getaddrinfo failed every single time. Mine only seems to fail once or twice every 24-48 hours or longer even. I hope to have more information after this weekend while I leave some tests running.