Skip to content

Handle tcache init failures gracefully#81

Merged
guangli-dai merged 1 commit intofacebook:devfrom
lexprfuncall:fix-tcache-init
Mar 9, 2026
Merged

Handle tcache init failures gracefully#81
guangli-dai merged 1 commit intofacebook:devfrom
lexprfuncall:fix-tcache-init

Conversation

@lexprfuncall
Copy link

tsd_tcache_data_init initializes the per-thread tcache and returns true on failure but, currently, its callers ignore this return value and will proceed with an uninitialized tcache following an failure.

This change updates all of its callers to check for init failure and print an error message. If opt_abort is set, it will also abort immediately. Otherwise, it simply disables the tcache for that thread and returns an error.

Also, unit tests have been added to cover both the abort and non-abort paths. To make failures testable, tcache_stack_alloc was refactored into a function pointer so tests can swap-in an allocator stub that always fails.

guangli-dai

This comment was marked as duplicate.

@lexprfuncall lexprfuncall force-pushed the fix-tcache-init branch 2 times, most recently from 44fc3f4 to ae74bf2 Compare March 5, 2026 02:08
tsd_tcache_data_init() returns true on failure but its callers ignore
this return value, leaving the per-thread tcache in an uninitialized
state after a failure.

This change disables the tcache on an initialization failure and logs
an error message.  If opt_abort is true, it will also abort.

New unit tests have been added to test tcache initialization failures.
@guangli-dai
Copy link

Discussed offline, now that we have exposed the boolean value for utility functions, sorting out the error message for the mallctl is another task and will be followed up in a separate PR.

@guangli-dai guangli-dai merged commit dc429af into facebook:dev Mar 9, 2026
155 of 156 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants