buglwIP - A Lightweight TCP/IP stack - Bugs: bug #62071, [LINGER] lwip_close() function...

 
 

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

bug #62071: [LINGER] lwip_close() function never returns

Submitter:  Ilgiz <wanderer>
Submitted:  Thu 17 Feb 2022 06:47:06 AM UTC
   
 
Category:  TCP Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Planned Release:  None
lwIP version:  2.1.3

Thu 17 Feb 2022 06:47:06 AM UTC, original submission:  

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.

Ilgiz <wanderer>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #52871:  targe_1.c added by wanderer (1KiB - text/plain)
file #52872:  targe_2.c added by wanderer (1KiB - text/plain)
file #52873:  main_1.c added by wanderer (2KiB - text/plain)
file #52874:  main_2.c added by wanderer (2KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by wanderer (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-02-17 wanderer Attached File- Added targe_1.c, #52871
        Attached File- Added targe_2.c, #52872
        Attached File- Added main_1.c, #52873
        Attached File- Added main_2.c, #52874

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code