Fix an issue where the rack app was being re-initialised for every request #1322
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This took me a while to track down, but when we switched over to using memcached based seasions using the dalli gem we noticed that we were leaking memcache connections:
The culprit was this bit of code: https://github.com/petergoldstein/dalli/blob/main/lib/rack/session/dalli.rb#L70
As Hanami was re-initalising the app on every single request:
https://github.com/hanami/hanami/blob/1.3.x/lib/hanami/middleware_stack.rb#L52
Because the call method on for the rack builder was calling
to_app
on every request:https://github.com/rack/rack/blob/da03bfab6497ab05e9ed795f5d3c033e47927483/lib/rack/builder.rb#L276
I am not sure if this is the correct way to fix this? or it was intended that the rack app should be re-initalised on every request?
Also I am not sure if this is present in Hanami v2 either