Skip to content

Conversation

kfindeisen
Copy link
Member

This PR defers initialization of RecordFactoryContextAdapter._store.context to ensure that each thread sees the correct initial state (an empty mapping). This prevents a bug where attempts to log from any thread other than the main one raised an AttributeError.

@kfindeisen kfindeisen marked this pull request as ready for review October 12, 2023 23:54
Putting the context in a property lets most of the factory's code be
agnostic to the use of thread-local storage, and also gives us more
control over how the context is initialized for each thread.
Since threading.local objects don't provide a happens-before guarantee
for their initial state, they must be initialized in the thread that
will use them. Lazy initialization on first use provides an easy way to
do this.
@kfindeisen kfindeisen merged commit 397c4bd into main Oct 13, 2023
@kfindeisen kfindeisen deleted the tickets/DM-41084 branch October 13, 2023 17:00
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.

2 participants