rails-lambda / lamby

🐑🛤 Simple Rails & AWS Lambda Integration
https://lamby.cloud
MIT License
602 stars 29 forks source link

Perform closing hooks on request #85

Closed nitsujri closed 3 years ago

nitsujri commented 3 years ago

Description

Solves https://github.com/customink/lamby/issues/84.

Handlers for Webrick and cgi all perform a .close as part of their lifecycle. A key function in the close hook is clear_query_cache.

We need to do the same.

Notes

Without this, one specific problem is ActiveRecord query_cache does not get cleared between requests easily causing stale data to be served back to clients.

metaskills commented 3 years ago

This is a great find. Will merge it in and get a release done.

metaskills commented 3 years ago

There were a few changes in master prior to this pull request which added Lamby handling ad-hoc events for EventBridge. As such, there could be simple IO objects returned vs Rack's. This cased a IOError test failure and my fix in https://github.com/customink/lamby/commit/0ba6fb063f8fac15859c9ac2cf28875b72e1aac2 is illustrated to behave below.

StringIO.new('sdfsaf').each { |part| part }.tap{ |x| x.close }
=> #<StringIO:0x00007f9bf4bb6010>
StringIO.new('sdfsaf').tap{ |x| x.close }.each { |part| part }
IOError: not opened for reading

Please let me know if you see any issue with that commit and moving the close method around.

metaskills commented 3 years ago

Just pushed v2.8.0 to rubygems

nitsujri commented 3 years ago

Yep this works great! Thanks for that.