[bug #56147] lwip_select() does not always wakup on received data

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #56147] lwip_select() does not always wakup on received data

Wilfred
URL:
  <https://savannah.nongnu.org/bugs/?56147>

                 Summary: lwip_select() does not always wakup on received data
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: jpa
            Submitted on: Wed 17 Apr 2019 02:42:23 PM UTC
                Category: sockets/netconn
                Severity: 3 - Normal
              Item Group: Faulty Behaviour
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: Other

    _______________________________________________________

Details:

This pseudocode would result in lwip_select() waking up for data received once
(if less than 1000 bytes), but not second time data is received:

while( 1 )
{
   lwip_select( maxfdp1, &readset, NULL, NULL, NULL);
   lwip_read( s, pData, 1000 );
}


The reason is that when first data is read with lwip_read(), the loop in
lwip_recv_tcp() is not exited resulting in calling
netconn_recv_tcp_pbuf_flags() twice which will call:
   ->netconn_recv_data_tcp()
      ->netconn_recv_data()
          ->API_EVENT(conn, NETCONN_EVT_RCVMINUS, len);

That results in decrementing the sock->rcvevent twice which, if only one
receive event has occured, will then be -1. So next receive event will restore
it to 0, but select() won't wake since it should be >0.

A fix is to change the exit condition for the loop in lwip_recv_tcp() in
socket.c at line 1025 from

} while ((recv_left > 0) && !(flags & MSG_PEEK));

to

} while ((recv_left > 0) && !(flags & MSG_PEEK) && (sock->rcvevent > 0) );






    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?56147>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

[bug #56147] lwip_select() does not always wakup on received data

Wilfred
Follow-up Comment #1, bug #56147 (project lwip):

LWIP version 2.1.2
The line for the fix is incorrect in the original submission. It should be
line 1010.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?56147>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

[bug #56147] lwip_select() does not always wakup on received data

Wilfred
Follow-up Comment #2, bug #56147 (project lwip):

Time for lwIP is short lately for all "active" members of the team, so if you
could provide a patch fixing this (I haven't reproduced this, yet)...

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?56147>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

[bug #56147] lwip_select() does not always wakup on received data

Wilfred
Additional Item Attachment, bug #56147 (project lwip):

File name: 0001-Fixed-problem-in-LWIP-where-select-did-not-always-wa.patch
Size:1 KB
   
<https://savannah.nongnu.org/file/0001-Fixed-problem-in-LWIP-where-select-did-not-always-wa.patch?file_id=46910>



    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?56147>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

[bug #56147] lwip_select() does not always wakup on received data

Wilfred
Follow-up Comment #3, bug #56147 (project lwip):

Ok, so reading the patch you attached, this is something fixed in master but
not fixed for 2.1.2? If so, please do cherry-picking properly: leave the
commit message intact and add a correct commit hash from master that you
picked from.

Ideally, point us to the bug # of the fix here, too.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?56147>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

Re: [bug #56147] lwip_select() does not always wakup on received data

Joel Pålsson
Hello Simon,

We have a local master branch that is using LWIP as upstream. I have made the fix here locally on our master and the patch is from there.
I got no idea how to add the fix in LWIP master. Can't you use the path set to add the fix to LWIP master?

Best Regards,
Joel

-----Original Message-----
From: Simon Goldschmidt <[hidden email]>
Sent: den 16 maj 2019 20:07
To: Joel Pålsson <[hidden email]>; Simon Goldschmidt <[hidden email]>; [hidden email]; [hidden email]
Subject: [bug #56147] lwip_select() does not always wakup on received data

Follow-up Comment #3, bug #56147 (project lwip):

Ok, so reading the patch you attached, this is something fixed in master but not fixed for 2.1.2? If so, please do cherry-picking properly: leave the commit message intact and add a correct commit hash from master that you picked from.

Ideally, point us to the bug # of the fix here, too.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?56147>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/

_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel