lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] The issue about gethostbyname() function


From: Joel Cunningham
Subject: Re: [lwip-users] The issue about gethostbyname() function
Date: Tue, 12 Jan 2016 21:50:57 +0000 (GMT)

I took a quick look at this and it appears to be a bug to me.  The code in lwip_gethostbyname() is attempting to determine "did we fail to initiate the DNS query?" by comparing with the result to ERR_INPROGRESS.  In that case the found callback won't be ran and application will never be signaled.  In the case you've outlined below, the found callback is running before netconn_gethostbyname_addrtype() finishes execution and it encounters an error.  This falsely trips the error handling in netconn_gethostbyname() and creates the double signaling.  To my knowledge the sys arch layer isn't expected to be able to call signal again on a semaphore.

It would be appropriate to open a bug for this issue at: https://savannah.nongnu.org/bugs/?func=additem&group=lwip.

Seems like to fix it correctly, we will need better failure communication to differentiate a failure start the query vs a failure in the query callback

Joel

On Jan 12, 2016, at 12:19 PM, address@hidden wrote:

I have a project using lwip stack with uCOS-III RTOS. lwip version is lwip-37bb0b89f062ed4fc47f0e42146dfdb065e1d6c4 that is from git.

My application thread priority is higher than lwip tcpip_thread priority.

When application  call gethostbyname(),  My RTOS detect the parameter *sem of sys_sem_signal() is uncorrect object type. After debug,  I find the problem.

The gethostbyname() calling procedure is that:


    lwip_gethostbyname()
         netconn_gethostbyname_addrtype()


              tcpip_callback(lwip_netconn_do_gethostbyname, &API_VAR_REF(msg));

              sys_sem_wait(API_EXPR_REF_SEM(API_VAR_REF(msg).sem));

              sys_sem_free(API_EXPR_REF(API_VAR_REF(msg).sem));



When application thread execute to sys_sem_wait() above, it will block.

Then lwip tcpip_thread will call lwip_netconn_do_gethostbyname(msg)  function whose calling procedure is that:

   

    lwip_netconn_do_gethostbyname()


         dns_gethostbyname_addrtype()

               dns_enqueue()

                     dns_check_entry()               dns.c:1379

                           dns_send()                     dns.c:985

                                 dns_call_found()      dns.c:735

lwip_netconn_do_dns_found(arg)   dns.c:899

       msg->err = ERR_VAL

                                                 sys_sem_signal(msg->sem)




After calling sys_sem_signal(msg->sem) function,   application  thread will run again immediately since its priority is higher than lwip tcpip_thread.  Then application  thread will free msg->sem by calling sys_sem_free().

Once lwip tcpip_thread continue to run,  lwip_netconn_do_gethostbyname() will check msg->err if unequal to ERR_INPROGRESS. Because msg->err is set to ERR_VAL above, so sys_sem_signal(msg->sem) will be called.However,  msg->sem is freed already.


This output info by usart is that:

      dns_enqueue: "http://www.baidu.com": use DNS entry 0
      dns_enqueue: "http://www.baidu.com": use DNS pcb 0
      dns_send: dns_servers[0] "http://www.baidu.com": request
      lwip_gethostbyname(http://www.baidu.com) failed, err=-6
      Could not find host http://www.baidu.com
      sys_sem_signal: err:24004



_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users


reply via email to

[Prev in Thread] Current Thread [Next in Thread]