tasklwIP - A Lightweight TCP/IP stack - Tasks: task #16124, [LINGER] lwip_close() function...

 
 

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

task #16124: [LINGER] lwip_close() function never returns

Submitter:  Ilgiz <wanderer>
Submitted:  Wed 16 Feb 2022 09:01:43 AM UTC
   
 
Category:  TCP Should Start On:  Wed 16 Feb 2022 12:00:00 AM UTC
Should be Finished on:  Wed 16 Feb 2022 12:00:00 AM UTC Priority:  5 - Normal
Status:  Cancelled Privacy:  Public
Assigned to:  None Percent Complete:  0%
Open/Closed:  Closed Planned Release:  None
Effort:  0.00

Thu 17 Feb 2022 06:53:34 AM UTC, comment #3: 

I have created a bug report #62071. The current request can be closed. Thanks.

Ilgiz <wanderer>
Wed 16 Feb 2022 08:35:37 PM UTC, comment #2: 

Sory, I think only the platform admins can move things. Would you mind just adding a new bug entry? I can then close this one.

Simon Goldschmidt <goldsimon>
Group administrator
Wed 16 Feb 2022 09:09:08 AM UTC, comment #1: 

I'm sorry, but this is not a request. This should be posted in the Bugs section. How is it possible to move it?

Ilgiz <wanderer>
Wed 16 Feb 2022 09:01:43 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):
TCP connection is established(pcb->state==ESTABLISHED) and no unsent and unacked data (conn->pcb.tcp->unsent==NULL&& conn->pcb.tcp->unacked==NULL)->call lwip_shutdown(socket,SHUT_WR)->enable linger with timeout by calling lwip_setsockopt()->without any delay call lwip_close()->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):
TCP connection is established(pcb->state==ESTABLISHED),no unsent and unacked data (conn->pcb.tcp->unsent==NULL&& conn->pcb.tcp->unacked==NULL)->FIN received from remote(remote side started connection shutdown)->call lwip_shutdown(socket,SHUT_WR)->enable linger with timeout by calling lwip_setsockopt()->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 #52859:  targe_1.c added by wanderer (1KiB - text/plain)
file #52860:  targe_2.c added by wanderer (1KiB - text/plain)
file #52861:  main_1.c added by wanderer (2KiB - text/plain)
file #52862:  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 goldsimon (Posted a comment)
  • -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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-12-21 goldsimon Open/ClosedOpen Closed
    2022-02-17 goldsimon StatusNone Cancelled
    2022-02-16 wanderer Attached File- Added targe_1.c, #52859
        Attached File- Added targe_2.c, #52860
        Attached File- Added main_1.c, #52861
        Attached File- Added main_2.c, #52862

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code