Skip to content

Clean up thread-local memory - #3771

Merged
maddeleine merged 7 commits into
aws:mainfrom
maddeleine:thread_fix
Feb 14, 2023
Merged

maddeleine merged 7 commits into
aws:mainfrom
maddeleine:thread_fix

Conversation

@maddeleine

@maddeleine maddeleine commented Jan 21, 2023 •

Copy link
Copy Markdown
Contributor

Resolved issues:

resolves #3525

Description of changes:

Adds a pthread key so that we can clean up the allocated thread-local memory without having to call s2n_cleanup in every thread.
Also I re-wrote the init test to make it more clean and add more cases.

Call-outs:

Was floating the idea of having one key to cleanup all thread-local storage, but I don't like this design. It means that the destructor function would be called multiple times potentially, so that cleanup function must be idempotent. This isn't that big of a deal, but it feels kind of dangerous. I'd rather create a key for each type of data that is thread-local.

Testing:

Adds a test that shows that you can call s2n_init in a different thread without calling s2n_cleanup.
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 Jan 21, 2023
@maddeleine maddeleine changed the title Clean up thread-specific memory Clean up thread-local memory Jan 21, 2023
@maddeleine
maddeleine requested a review from lrstewart January 23, 2023 18:37
@toidiu
toidiu self-requested a review January 25, 2023 07:15
@grrtrr

grrtrr commented Jan 28, 2023

Copy link
Copy Markdown
Contributor

I closed #3530 since it turned out that calling InitAPI/ShutdownAPI from different threads is not a good idea.
Added a PR aws/aws-sdk-cpp#2314 with references to the 2 known problems that this causes.

@maddeleine

Copy link
Copy Markdown
Contributor Author

I closed #3530 since it turned out that calling InitAPI/ShutdownAPI from different threads is not a good idea. Added a PR aws/aws-sdk-cpp#2314 with references to the 2 known problems that this causes.

Thanks for the comment. We might decide to implement this fix even if it's not blocking anyone as it seems like a good idea.

@grrtrr

grrtrr commented Feb 8, 2023

Copy link
Copy Markdown
Contributor

I closed #3530 since it turned out that calling InitAPI/ShutdownAPI from different threads is not a good idea. Added a PR aws/aws-sdk-cpp#2314 with references to the 2 known problems that this causes.

There is now a third case where this condition is causing problems: awslabs/aws-c-io#478

@maddeleine

Copy link
Copy Markdown
Contributor Author

I closed #3530 since it turned out that calling InitAPI/ShutdownAPI from different threads is not a good idea. Added a PR aws/aws-sdk-cpp#2314 with references to the 2 known problems that this causes.

There is now a third case where this condition is causing problems: awslabs/aws-c-io#478

Are you suggesting that it is not a good idea to implement this fix? This change is technically unrelated to potential errors when calling InitAPI/ShutdownAPI from different threads.

@maddeleine
maddeleine requested review from camshaft and removed request for toidiu February 13, 2023 21:19
Comment thread docs/USAGE-GUIDE.md Resolved
Comment thread tests/unit/s2n_init_thread_test.c Resolved
@maddeleine
maddeleine requested a review from lrstewart February 14, 2023 19:50
@maddeleine
maddeleine enabled auto-merge (squash) February 14, 2023 22:36
@maddeleine
maddeleine merged commit fecd8a2 into aws:main Feb 14, 2023
@maddeleine
maddeleine deleted the thread_fix branch February 15, 2023 00:00
dougch pushed a commit to dougch/s2n-tls that referenced this pull request Feb 22, 2023
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.

s2n_random.c: memory leaks of per-thread rand state

4 participants