[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] [task #16124] [LINGER] lwip_close() function never returns
From: |
Ilgiz |
Subject: |
[lwip-devel] [task #16124] [LINGER] lwip_close() function never returns |
Date: |
Wed, 16 Feb 2022 04:01:45 -0500 (EST) |
URL:
<https://savannah.nongnu.org/task/?16124>
Summary: [LINGER] lwip_close() function never returns
Project: lwIP - A Lightweight TCP/IP stack
Submitted by: wanderer
Submitted on: Ср 16 фев 2022 09:01:43
Category: TCP
Should Start On: Ср 16 фев 2022 00:00:00
Should be Finished on: Ср 16 фев 2022 00:00:00
Priority: 5 - Normal
Status: None
Privacy: Public
Percent Complete: 0%
Assigned to: None
Open/Closed: Open
Discussion Lock: Any
Planned Release: None
Effort: 0.00
_______________________________________________________
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):
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.
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Ср 16 фев 2022 09:01:43 Name: targe_1.c Size: 1КиБ By:
wanderer
<http://savannah.nongnu.org/task/download.php?file_id=52859>
-------------------------------------------------------
Date: Ср 16 фев 2022 09:01:43 Name: targe_2.c Size: 1КиБ By:
wanderer
<http://savannah.nongnu.org/task/download.php?file_id=52860>
-------------------------------------------------------
Date: Ср 16 фев 2022 09:01:43 Name: main_1.c Size: 2КиБ By:
wanderer
<http://savannah.nongnu.org/task/download.php?file_id=52861>
-------------------------------------------------------
Date: Ср 16 фев 2022 09:01:43 Name: main_2.c Size: 2КиБ By:
wanderer
<http://savannah.nongnu.org/task/download.php?file_id=52862>
_______________________________________________________
Reply to this item at:
<https://savannah.nongnu.org/task/?16124>
_______________________________________________
Сообщение отправлено по Savannah
https://savannah.nongnu.org/
- [lwip-devel] [task #16124] [LINGER] lwip_close() function never returns,
Ilgiz <=