curl-users
curl get stuck when connect to and from the same ip/port
Date: Wed, 31 Oct 2018 14:36:34 +0900
Hi,
I am running curl in linux and I meet the following issue.
(curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8
libidn/1.32 librtmp/2.3)
curl pick up a local port to connect a remote port, but if the remote is
also in the same instance, there is a small possibility(around 1/10000)
that the selected local port is just the same with the remote port. It
means that there will be a TCP connection from and to the same ip/port and
the curl command will get stuck forever.
I am always able to reproduce this issue by the following bash.
for i in {1..100000}
do
curl -XPOST "http://localhost:8288/" -s -d "dummy"
done
Note that there is no need to setup any service listening to 8288 port,
when the above bash loops at some point, curl will get stuck.
At this time, if we check the process, we can find curl process is taking
up the 8288 port unexpected.
sudo netstat -pant | grep 8288
tcp 0 0 127.0.0.1:8288 127.0.0.1:8288
ESTABLISHED 4072/curl
(The situation is the same as
https://stackoverflow.com/questions/4949858/how-can-you-have-a-tcp-connection-back-to-the-same-port
)
A workaround is set timeout(-m) to the curl command, but I still think this
behaviour is strange and causes unexpected behaviour. I will appreciate if
anyone could give some insight about this issue.
Thanks in advance.
Wang Yan
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2018-10-31