buglwIP - A Lightweight TCP/IP stack - Bugs: bug #46185, UDP packets are not received after...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #46185: UDP packets are not received after socket rebind

Submitted by:  Andreas Toensfeuerborn <atoensfeuerborn>
Submitted on:  Mon 12 Oct 2015 06:43:48 AM UTC  
 
Category: UDPSeverity: 3 - Normal
Item Group: Faulty BehaviourStatus: Works For Me
Privacy: PublicAssigned to: None
Open/Closed: ClosedPlanned Release: None
lwIP version: 1.4.1

Mon 19 Oct 2015 06:03:27 AM UTC, comment #3:

It's not about timing constraints, it's about race conditions. Using one socket from 2 execution contexts (e.g. threads) is only supported in current git master with special settings enabled.

It should work when rebinding from the same thread.

Simon Goldschmidt <goldsimon>
Project Administrator
Mon 19 Oct 2015 05:55:26 AM UTC, comment #2:

It's actually a different thread. recvfrom is called in one thread, rebinding is done in a second thread.

What would be the correct sequence? Is it enough to just rebind it in the same thread, e.g. after the last unsuccessful call to recvfrom or are there other timing contraints that I must consider?

Andreas Toensfeuerborn <atoensfeuerborn>
Fri 16 Oct 2015 07:03:04 AM UTC, comment #1:

Which thread executes the close/socket/bind sequence? If this is not done by the recvfrom threads, you must know exactly what to do!

Simon Goldschmidt <goldsimon>
Project Administrator
Mon 12 Oct 2015 06:43:48 AM UTC, original submission:

In my application I use several interfaces (up to 32). The behaviour described below can be reproduced easier with more than 1 interface but occurs also with only 1 interface.

After startup, I create 2 UDP sockets for each interface but do not bind them because I do not know the IP address yet.

For each socket I have a separate receive thread calling "lwip_recvfrom". The function returns an error because the socket is not bound and I ignore the error.

At some point the sockets are bound to an IP address by calling
- lwip_close()
- lwip_socket()
- lwip_bind()

I have been using this kind of implementation with native sockets from Windows, Linux and VxWorks without any problems.

Most of the time the behaviour after that is correct and packets are received properly in the receive thread(s).
But sporadically received packets are not delivered to "lwip_recfrom".
The packet is transferred through functions "udp_input" to "recv_udp" but the mailbox does not deliver the packet to "netconn_recv_data" and therefore to "lwip_recfrom".

The behaviour is the same under Linux and Windows so I think the mailbox handling itself is not the source of the problem.

The error seems to occur in case the function "sys_mbox_trypost" is called before the function "lwip_recvfrom" (netconn_recv_data) is ready to receive the data.

I have attached to files with (also self made) debug outputs in case the connection is ok and not ok.
In case the connection is ok, "lwip_recvfrom" is called before "udp_input" after the rebind.
In case the connection is not ok, "udp_input" is called before "lwip_recvfrom".

Andreas Toensfeuerborn <atoensfeuerborn>

 

Attached Files
file #35162:  putty_ok.TXT added by atoensfeuerborn (181KiB - text/plain)
file #35163:  putty_nok.TXT added by atoensfeuerborn (317KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by atoensfeuerborn (Additional developer)
  • -unavailable- added by goldsimon (Posted a comment)
  • -unavailable- added by atoensfeuerborn (Submitted the item)
  • -unavailable- added by atoensfeuerborn
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 19 Oct 2015 06:03:27 AM UTCgoldsimonStatusNone=>Works For Me
      Open/ClosedOpen=>Closed
    Mon 19 Oct 2015 05:57:06 AM UTCatoensfeuerbornCarbon-Copy-=>Added -unavailable-
    Mon 12 Oct 2015 06:43:48 AM UTCatoensfeuerbornAttached File-=>Added putty_ok.TXT, #35162
      Attached File-=>Added putty_nok.TXT, #35163
      Carbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1