curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder Daniel himself.

Re: Three fixes for a share's connection pool used from several threads

From: Detlev Stalling via curl-library <curl-library_at_lists.haxx.se>
Date: Tue, 1 Dec 2026 17:22:27 +0000

On Tue, 1 Dec 2026, Daniel Stenberg wrote:

> You are knowingly using an API in a way that is documented as not
> supported, and by changing the code *slightly* you make it work for
> your use case, but you still don't want to make it thread-safe so
> that we can update the documentation.

I put that badly. I did not want to claim more than I have tested. It
would be great to get this to the point where the documentation can be
changed.

> So what is your new test(s) going to verify when it comes to using
> the connection pool in a threaded scenario that's not guaranteed to
> work according to the documentation?

Agreed, a test for something the documentation excludes makes no
sense. So first the guarantee, then a test that verifies it. My proposal
for the guarantee:

  Transfers in different threads can use the connection pool of a
  share, if the lock callbacks are set and no easy or multi handle is
  used by two threads at the same time. A connection is used by the
  transfers of one multi handle (or of one easy handle) at a time.
  Another thread only gets it when it is idle.

This does not include streams of one HTTP/2 connection in different
threads; CURLSHOPT_SHARE.md excludes that already. As far as I
can see, the rule in the code is: a connection in the pool is only
touched with the share lock held, unless a transfer is attached
to it, and then only by the thread that runs this transfer. The three
changes are the places where I found it broken.

One place I already know is broken is curl_easy_upkeep().
curl_easy_send() and curl_easy_recv() on connect-only connections
would need a look as well. We do not use any of these in our app, but
I could look into them too.

If that direction is acceptable, I would open the PRs for the three
changes, then add the stress test as a libtest case, also with HTTP/2,
so that the thread-sanitizer CI job runs it. When that is clean, the
documentation could be updated. Does this make sense?

Thanks,
Detlev


-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2026-12-01