Skip to content

Fix race condition in new_certs_dir output path#3095

Merged
justsmth merged 2 commits intoaws:mainfrom
justsmth:fix-ca-race-condition
Mar 13, 2026
Merged

Fix race condition in new_certs_dir output path#3095
justsmth merged 2 commits intoaws:mainfrom
justsmth:fix-ca-race-condition

Conversation

@justsmth
Copy link
Copy Markdown
Contributor

Description of changes:

outdirlen in caTool was never set after building the directory prefix, so it stayed at 0. This caused the cert filename (e.g. 01.pem) to be written to the current working directory instead of the configured new_certs_dir. When parallel test processes shared a working directory, they'd stomp on each other's 01.pem.

The fix sets outdirlen = strlen(new_cert) after constructing the directory prefix so certs land in the right place.

Also cleaned up TearDown to remove the files that now (correctly) end up inside new_certs_dir, and the auxiliary .old files the CA tool creates during serial/db rotation.

Call-outs:

This was a bug in ca.cc itself, not the test. Every openssl ca invocation was writing the new cert to the CWD — the test flakiness just happened to surface it.

Testing:

All 59 CATest tests pass. Verified via verbose output that certs now go to the temp directory (/tmp/awslcTestDir.../01.pem) instead of the CWD.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@justsmth justsmth changed the title [DRAFT] Fix race condition in new_certs_dir output path [DRAFT] Fix race condition in new_certs_dir output path Mar 12, 2026
@justsmth justsmth requested a review from skmcgrail March 12, 2026 14:56
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.14%. Comparing base (9124e2b) to head (d8450c8).
⚠️ Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
tool-openssl/ca_test.cc 85.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3095      +/-   ##
==========================================
- Coverage   78.16%   78.14%   -0.03%     
==========================================
  Files         689      689              
  Lines      121628   121695      +67     
  Branches    16982    16997      +15     
==========================================
+ Hits        95074    95094      +20     
- Misses      25670    25715      +45     
- Partials      884      886       +2     

☔ View full report in Codecov by Sentry.
📢 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.

@justsmth justsmth marked this pull request as ready for review March 12, 2026 17:09
@justsmth justsmth requested a review from a team as a code owner March 12, 2026 17:09
@justsmth justsmth changed the title [DRAFT] Fix race condition in new_certs_dir output path Fix race condition in new_certs_dir output path Mar 12, 2026
@WillChilds-Klein WillChilds-Klein self-requested a review March 12, 2026 19:48
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Comment on lines +124 to +129
unlink(file_path.c_str());
}
}
closedir(d);
}
rmdir(dir_path);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to account for failure conditions here? it's a test, so probably not...

@justsmth justsmth merged commit 048d5ef into aws:main Mar 13, 2026
481 of 485 checks passed
@justsmth justsmth deleted the fix-ca-race-condition branch March 13, 2026 21: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.

4 participants