lwip-devel
[Top][All Lists]
Advanced

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

[lwip-devel] [bug #62071] [LINGER] lwip_close() function never returns


From: Ilgiz
Subject: [lwip-devel] [bug #62071] [LINGER] lwip_close() function never returns
Date: Thu, 17 Feb 2022 01:47:08 -0500 (EST)

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

                 Summary: [LINGER] lwip_close() function never returns
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: wanderer
            Submitted on: Чт 17 фев 2022 06:47:06
                Category: TCP
                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: 2.1.3

    _______________________________________________________

Details:

Hi,
I tried to use the linger option in my application, but encountered random
freezes. After some investigation, it was found that the lwip_close() function
never returns if linger is enabled with a non-zero timeout. But this does not
happen regularly, the stars must converge in the sky. It was found that the
hang occurs in two scenarious.

First scenario (Active close):
1) TCP connection is established(pcb->state==ESTABLISHED) and no unsent and
unacked data (conn->pcb.tcp->unsent==NULL&& conn->pcb.tcp->unacked==NULL);
2) Call lwip_shutdown(socket,SHUT_WR);
3) Enable linger with timeout by calling lwip_setsockopt()
4) Without any delay call lwip_close()
5) The other side normally closed the connection before the linger timeout
occurs.
 In this case, tcp will be deallocated (moved to tcp_tw_pcbs list and after
deallocated in tcp_slowtmr()) so that the api_msg.c layer will never know
about it.

Second scenario (Passive close):
1)TCP connection is established(pcb->state==ESTABLISHED),no unsent and unacked
data (conn->pcb.tcp->unsent==NULL&& conn->pcb.tcp->unacked==NULL);
2)FIN received from remote(remote side started connection shutdown);
3)Call lwip_shutdown(socket,SHUT_WR);
4)Enable linger with timeout by calling lwip_setsockopt();
5)Without any delay call lwip_close(); 
Important there was no call to the lwip_recv() function between getting FIN
and calling lwip_setsockopt, lwip_close. Calling lwip_recv() changes the
behavior due to the TF_RXCLOSED flag set.

Also in both scenarios, the unsent and unpacked lists must be empty before the
shutdown operation begins. Otherwise everything works fine (lwip_close() does
not freeze).

To reproduce and understand, I have prepared code snippets for the device
(lwIP) and PC (Windows).

To reproduce the first scenario:
target_1.c - snippet code for targe with LwIP;
main_1.c - full application(server) for PC (Windows);

To reproduce the second scenario:
target_2.c - snippet code for targe with LwIP;
main_2.c - full application(server) for PC (Windows);

The application on the PC side must be started before the target. 



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Чт 17 фев 2022 06:47:06  Name: targe_1.c  Size: 1КиБ   By:
wanderer

<http://savannah.nongnu.org/bugs/download.php?file_id=52871>
-------------------------------------------------------
Date: Чт 17 фев 2022 06:47:06  Name: targe_2.c  Size: 1КиБ   By:
wanderer

<http://savannah.nongnu.org/bugs/download.php?file_id=52872>
-------------------------------------------------------
Date: Чт 17 фев 2022 06:47:06  Name: main_1.c  Size: 2КиБ   By:
wanderer

<http://savannah.nongnu.org/bugs/download.php?file_id=52873>
-------------------------------------------------------
Date: Чт 17 фев 2022 06:47:06  Name: main_2.c  Size: 2КиБ   By:
wanderer

<http://savannah.nongnu.org/bugs/download.php?file_id=52874>

    _______________________________________________________

Reply to this item at:

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

_______________________________________________
  Сообщение отправлено по Savannah
  https://savannah.nongnu.org/




reply via email to

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