cURL / Mailing Lists / curl-library / Single Mail


Re: SO_REUSEADDR and multi-threaded environment

From: Daniel Stenberg <>
Date: Wed, 2 Jul 2014 23:21:37 +0200 (CEST)

On Tue, 1 Jul 2014, Sachin Nikumbh wrote:

> I have a client application that's using libcurl to communicate with a
> proprietary server. I am testing the application in multi-threaded
> environment and how it scales with the number of threads.

I don't think this is really related to multi threading though, more like how
many parallell connections you try to use in how short time period.

> At around 30000 number of threads, some of the requests started failing
> with "Couldn't connect the server error" which I am assuming is happening
> because my application is failing to find any more ports to bind to.

That seems reasonable, yes. strace would of course tell you exactly which
syscall that fails.

> I decided to set the SO_REUSEADDR socket option in a hope to reuse the
> sockets in the TIME_WAIT state. Following is a snippet of my code that I
> wrote to set SO_REUSEADDR socket option:


> But the behavior of my application is not changing.

I'm not an expert on SO_REUSEADDR, but perhaps that's too late to set that

List admin:
Received on 2014-07-02