I was noticing some issues with Thread.local code when it came to setting / clearing headers when running multiple Puma workers. This was tracked down to a few things:
Changes
Using Hash#replace mutated the headers hash instead of just replacing it with the custom_headers value.
Using Resource.with_headers(...) would clear out custom headers instead of just resetting them to their original value.
Thread.current was not clearing when using Puma. Moved to using request_store to handle these technical hurdles.
Background
I was noticing some issues with
Thread.local
code when it came to setting / clearing headers when running multiple Puma workers. This was tracked down to a few things:Changes
Hash#replace
mutated the headers hash instead of just replacing it with the custom_headers value.Resource.with_headers(...)
would clear out custom headers instead of just resetting them to their original value.Thread.current
was not clearing when using Puma. Moved to using request_store to handle these technical hurdles.