fix(ssl): serialize ssl operations with a process-wide file lock#498
Open
mrrobot47 wants to merge 1 commit into
Open
fix(ssl): serialize ssl operations with a process-wide file lock#498mrrobot47 wants to merge 1 commit into
mrrobot47 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Nothing serialized SSL operations. A cron
ssl-renew --allrunning concurrently with a manualee site ssl/ssl-verify(or two crons) would read/write the samecertificate_order.json,account/key.private.pem, andacme-conf/var/{domain}/*— risking corrupted JSON, duplicate ACME orders, and account-key overwrites. No flock existed anywhere on the SSL path.Fix
Acquire a single global, exclusive, non-blocking
flock(EE_ROOT_DIR/ssl-global.lock) at the three ACME entry points —init_le()(beforeregister()/authorize()write account/order state),ssl_verify(), andssl_renew(). A concurrent SSL operation in another process fails fast with a clear "another SSL operation is already in progress" error instead of racing. The lock is held for the whole operation and released automatically on process exit (advisory flock — crash-safe).The handle is a process-level
staticwith a reentrancy short-circuit, and this is load-bearing:ssl-renew --alldispatches each site viaEE::run_commandin one process (a fresh command instance per site), andflockdenies a second lock on the same file via a different fd even within the same process — so an instance-level guard would make site #2 of--allwrongly error. The static handle means the first acquire locks and every later/nested acquire (init_le → ssl_verify; each--allsite) returns reentrantly. (It intentionally differs from the backup lock's instance handle + blocking wait + explicit release: SSL's--all-in-one-process pattern needs a process-wide handle, fail-fast for cron, and no per-site release.)Testing
Manual: start a long
ee site create <le-site>(orssl-renew --all) and concurrently runee site ssl-verify <other>→ the second exits immediately with the "in progress" error; sequential runs and--all(many sites in one process) work normally.