curl / Mailing Lists / curl-users / Single Mail


curl get stuck when connect to and from the same ip/port

From: 王岩 <>
Date: Wed, 31 Oct 2018 14:36:34 +0900


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}
  curl -XPOST "http://localhost:8288/" -s -d "dummy"

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
(The situation is the same as

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

Received on 2018-10-31