Open file handles spec is flaky
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:
lsofis 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.
lsofitself notes that the+Dmode is inefficient and resource hungry.
Potential actions:
- Filter
open_filesto those with a PID that matchesProcess.pid - Use a more specific path
- Include additional paths like /tmp
- Remove the spec or make it a warning?
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.
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.