Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(s2n_session_ticket_test): correct clock mocking #4602

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

jmayclin
Copy link
Contributor

Resolved issues:

Perhaps addresses #4600

Description of changes:

We have observed that the session_ticket_test is flaky. I have a hypothesis that the flakiness occurs under this scenario

  1. s2n_config_add_ticket_crypto_key is called with intro time of 0
  2. wall_clock is called to set the intro time of the key, let say 1_000 ns.
  3. during the handshake, s2n_get_ticket_encrypt_decrypt_key is called to get an encryption key
  4. wall_clock returns the same time, or a smaller time <= 1_000 ns which is possible because wall clocks can move backwards.
  5. therefore no encryption key is found
  6. and no session ticket is sent.

We fix this with two changes
First, we mock the time before adding the ticket key, ensuring that we know exactly what the ticket intro time is.
Secondly, we allow keys to be used at their intro time, rather than enforcing keys be past their intro time.

Call-outs:

It's incredibly difficult to test whether this is causing the actual flakiness, but by mocking the wall clock I can confirm that the above sequence of events is 100% possible.

Testing:

All CI should pass. By mocking the wall clock at the start of the test, I now have test coverage over the <= condition that I added.

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

@github-actions github-actions bot added the s2n-core team label Jun 12, 2024
@jmayclin jmayclin requested review from goatgoose and maddeleine June 12, 2024 23:37
@jmayclin jmayclin marked this pull request as ready for review June 12, 2024 23:38
Copy link
Contributor

@lrstewart lrstewart left a comment

Choose a reason for hiding this comment

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

Did you try running the test in a loop for a while? Were you able to repro the failure at all?

tls/s2n_resume.c Outdated Show resolved Hide resolved
Co-authored-by: Lindsay Stewart <stewart.r.lindsay@gmail.com>
@jmayclin
Copy link
Contributor Author

I did try running the test in a loop, but was unable to reproduce the failure locally. 😢

So this definitely fixes a theoretical problem, and maybe a real one, so I'm content to move ahead with it.

If we were fine with artifical clock skew, I could add fake noise to the wall clock measurement, and then my changes would successfully fix it.

@jmayclin jmayclin enabled auto-merge (squash) June 17, 2024 19:49
@jmayclin jmayclin merged commit 38cb293 into aws:main Jun 17, 2024
33 checks passed
@jmayclin jmayclin deleted the fix-flaky-attempt branch July 1, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants