Skip to content

Hold MBEDTLSLOCK while ca_chain!, own_cert! and set_alpn! change a config - #319

Merged
quinnj merged 1 commit into
masterfrom
jq/lock-config-setters
Oct 23, 2026
Merged

quinnj merged 1 commit into
masterfrom
jq/lock-config-setters

Conversation

@quinnj

@quinnj quinnj commented Oct 23, 2026

Copy link
Copy Markdown
Member

ca_chain!, own_cert! and set_alpn! replace what handshake steps read (conf->ca_chain, the own-cert list, conf->alpn_list), and the GC can then free the replaced chain or ALPN list. A handshake step on another thread that already read the old pointer could use it after it's freed. The window is narrow: the GC has to run during one of that step's Julia callbacks (f_verify, say).

This matters because HTTP.jl 1.x calls ca_chain! on its shared global config for every new connection when HTTP_CA_BUNDLE or CURL_CA_BUNDLE is set (Connections.jl, global_sslconfig). The setters now hold MBEDTLSLOCK (#315), so a swap waits for any in-flight handshake step, and later steps only see the new value.

To be clear, this is a defensive fix: I couldn't make master crash. 2,400 threaded handshakes with the chain swapped and fully GC'd in a loop all succeeded, on master and with this change. The fix rests on reading the code. The cost is that these setters wait for a running handshake step.

Found by a fourth independent review pass (as plausible).

🤖 Generated with Claude Code

…nfig

These replace what handshake steps read, and the GC can free the replaced chain or ALPN
list. Without the lock, a handshake step on another thread could be using the old one when
it's replaced. HTTP.jl sets the chain of its shared config for every connection when
HTTP_CA_BUNDLE is set, so this happens in practice; the lock makes the swap wait for the
step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.97%. Comparing base (0fe84e1) to head (33eb7f9).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #319      +/-   ##
==========================================
+ Coverage   88.93%   88.97%   +0.03%     
==========================================
  Files          12       12              
  Lines         904      907       +3     
==========================================
+ Hits          804      807       +3     
  Misses        100      100              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@quinnj
quinnj merged commit c8123ed into master Oct 23, 2026
9 checks passed
@quinnj
quinnj deleted the jq/lock-config-setters branch October 23, 2026 20:46
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.

1 participant