-
Notifications
You must be signed in to change notification settings - Fork 36
Description
Summary
If you use lograge-sql together with solid cable there is a memory leak, because the queries that solid cable makes are stored by lograge-sql, but never logged and thus retained in memory. Since solid will be the default action cable adapter from Rails 8 onwards, I think it would be best to filter these queries by default.
Details
After deploying solid cable wie noticed a constant memory increase:
Inspection of the heap showed that a significant amount of memory was being used by this gem:
> heapy diff heap-1.json heap-2.json heap-3.json | grep Retained | head -4
Retained STRING 140849 objects of size 45071432/52941087 (in bytes) at: /usr/local/bundle/gems/lograge-sql-2.4.0/lib/lograge/sql.rb:54
Retained STRING 17676 objects of size 913880/52941087 (in bytes) at: /usr/local/bundle/gems/activerecord-7.1.4.2/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb:20
Retained DATA 7631 objects of size 610480/52941087 (in bytes) at: /usr/local/bundle/gems/activerecord-7.1.4.2/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb:96
Retained IMEMO 7343 objects of size 616616/52941087 (in bytes) at: /usr/local/bundle/gems/activerecord-7.1.4.2/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb:96The retained strings in the heap snapshot are actually all polling queries by solid cable. I think what happens is, that these queries are stored here, but never get cleared because they are outside of a request context.
Possible solutions
- Since solid cable will be the default action cable adapter and these queries don't add much value anyway, I think it would be best to skip storing these queries by default. I'm not sure if a configuration option to disable this behavior is even necessary.
- Another solution would be to allow passing a lambda function, to determine whether a query should be stored, but then everyone would have to discover this leak for themselves.
I'm happy to open a PR once we've agreed on how to proceed!
