Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import_scan function leaves behind open file handles #190

Closed
kmm-r7 opened this issue Oct 23, 2015 · 1 comment · Fixed by #191
Closed

import_scan function leaves behind open file handles #190

kmm-r7 opened this issue Oct 23, 2015 · 1 comment · Fixed by #191

Comments

@kmm-r7
Copy link

kmm-r7 commented Oct 23, 2015

I ran into a problem with the removal of temporary files created during a run of an import script I wrote for a customer, which seems to primarily affect Windows due to a difference in file locking behavior.

At https://github.com/rapid7/nexpose-client/blob/master/lib/nexpose/scan.rb#L410, the file is opened using File.new, but is not closed, leaving behind an open handle with no primary references outside of the global ObjectSpace instance.
Windows interprets the open handle as locked and in use, preventing removal of the file referenced.

I worked around this by iterating through open IO handles in ObjectSpace and closing them, but the behavior is a bit confusing and took me some time to track down.

The fix should trivial, just a matter of adding "scan.close" before the function returns to close the handle.

@gschneider-r7
Copy link
Contributor

I think I'll just change this code to use a block so the file is closed automatically without having to worry about rescuing on any errors. The export method is done that way already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants