Skip to content

fix(rest): make HttpClient safe for concurrent requests - #19

Open
smaheshwar-pltr wants to merge 1 commit into
mainfrom
fix/rest-http-client-thread-safety
Open

smaheshwar-pltr wants to merge 1 commit into
mainfrom
fix/rest-http-client-thread-safety

Conversation

@smaheshwar-pltr

@smaheshwar-pltr smaheshwar-pltr commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #20.

Each request now takes a cpr::ConnectionPool that no other request is using and returns it afterwards, so connections are still reused. HttpResponse now copies the status, body and headers out of cpr::Response, whose curl handle must be freed before its pool is reused. This also stops libcurl from evicting connections when more than five requests are in flight (its default CURLOPT_MAXCONNECTS).

The new test crashes without the fix on some libcurl versions, such as 8.22.0, but not on 8.18.0, which CI uses.

🤖 Generated with Claude Code

HttpClient sent every request through one cpr::ConnectionPool, and
libcurl does not support sharing a connection cache between threads.
Overlapping requests, for example from token refresh or the metrics
executor, could crash. Give each in-flight request its own pool and
reuse idle pools.

HttpResponse now copies the status, body and headers out of
cpr::Response, whose curl handle must be freed before its pool is
reused.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@smaheshwar-pltr
smaheshwar-pltr force-pushed the fix/rest-http-client-thread-safety branch from 14c719e to dee5b68 Compare September 25, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RestCatalog: concurrent HTTP requests can crash in libcurl

1 participant