Skip to content

Open file handles spec is flaky #975

@dlpierce

Description

@dlpierce

it "doesn't leave a file handle open on upload/find_by" do
# No file handle left open from upload.
resource = Valkyrie::Specs::CustomResource.new(id: "testdiscovery")
pre_open_files = open_files
uploaded_file = storage_adapter.upload(file: file, original_filename: 'foo.jpg', resource: resource, fake_upload_argument: true)
file.close
expect(pre_open_files.size).to eq open_files.size
# No file handle left open from find_by
pre_open_files = open_files
the_file = storage_adapter.find_by(id: uploaded_file.id)
expect(the_file).to be_kind_of Valkyrie::StorageAdapter::File
expect(pre_open_files.size).to eq open_files.size
end
def open_files
`lsof +D .`.split("\n").map { |r| r.split("\t").last }
end

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions