Skip to content

Fix windows file descriptor leak #4023

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

Merged
merged 2 commits into from
Oct 22, 2019

Conversation

Gallaecio
Copy link
Member

Fixes #3391

@Gallaecio Gallaecio force-pushed the fix-windows-file-descriptor-leak branch from 4b8dfc9 to b3c0141 Compare September 17, 2019 08:42
@Gallaecio Gallaecio changed the title [WIP] Fix windows file descriptor leak Fix windows file descriptor leak Sep 17, 2019
@Gallaecio Gallaecio requested a review from dangra September 17, 2019 08:44
@codecov
Copy link

codecov bot commented Sep 17, 2019

Codecov Report

Merging #4023 into master will not change coverage.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master    #4023   +/-   ##
=======================================
  Coverage   85.52%   85.52%           
=======================================
  Files         167      167           
  Lines        9741     9741           
  Branches     1461     1461           
=======================================
  Hits         8331     8331           
  Misses       1153     1153           
  Partials      257      257
Impacted Files Coverage Δ
scrapy/extensions/feedexport.py 81.65% <100%> (ø) ⬆️

@@ -242,7 +242,7 @@ def open_spider(self, spider):
def close_spider(self, spider):
slot = self.slot
if not slot.itemcount and not self.store_empty:
return
return defer.maybeDeferred(slot.storage.store, slot.file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain how this fix works?

Copy link
Member Author

@Gallaecio Gallaecio Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In FeedExporter.open_spider we are opening the output file, regardless of the value of self.store_empty. slot.storage.store is responsible for closing that file; see scrapy.extensions.feedexport.FileFeedStorage.store.
The code here, however, was skipping that step when there was no item to store and storing an empty file was disabled. And that was a problem on Windows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, this makes sense. Could you please add a small comment here though? Now I see that this is a copy-paste of the code below (d = defer.maybeDeferred(slot.storage.store, slot.file)). But it is not obvious, from these few lines themselves, that slot.storage.store closes a file.

@Gallaecio Gallaecio merged commit 1d5c270 into scrapy:master Oct 22, 2019
@Gallaecio Gallaecio deleted the fix-windows-file-descriptor-leak branch October 22, 2019 13:13
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 this pull request may close these issues.

File descriptor leak in FeedExporter
2 participants