valkyrie icon indicating copy to clipboard operation
valkyrie copied to clipboard

Open file handles spec is flaky

Open dlpierce opened this issue 1 year ago • 2 comments

https://github.com/samvera/valkyrie/blob/814494dca82c87b517b31e7d2c3024b41440919e/lib/valkyrie/specs/shared_specs/storage_adapter.rb#L55-L72

This spec frequently fails, occasionally even during CI. This is also true for downstream application's custom storage adapters since this is a shared spec.

Currently the check uses lsof +D to list all open files within the application directory. Issues with this include:

  • lsof is an additional system level dependency
  • If a storage adapter stashes files in a location outside the application dir tree (e.g. /tmp) then those would be missed.
  • Other (even non-ruby) processes are included in the open file list.
  • lsof itself notes that the +D mode is inefficient and resource hungry.

Potential actions:

  • Filter open_files to those with a PID that matches Process.pid
  • Use a more specific path
  • Include additional paths like /tmp
  • Remove the spec or make it a warning?

dlpierce avatar Dec 10 '24 19:12 dlpierce

Ooh, I like the pid idea.

I've thought about this one a lot too, since it fails for me locally basically always. We were just leaking SO MANY handles before this test, so I'm scared to remove it.

tpendragon avatar Dec 10 '24 21:12 tpendragon

Yeah, I think it's a valuable test to have. I've been pondering how it would fail in a CI situation where there shouldn't be other processes. Maybe if there is an open file that is missing a corresponding close then if garbage collection doesn't trigger during the spec it would show as a spec failure? We could explicitly garbage collect in open_files I guess? Or maybe we want to be identifying these problems better if that is really what's happening.

dlpierce avatar Dec 11 '24 14:12 dlpierce