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

fix(files): close mmap in abstract file _prefetch #70707

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JoshFerge
Copy link
Member

we seem to have a lot of warnings about this function and unclosed sockets. reading python docs, it seems like we should close this mmap. I'm not quite sure if this is the source of the log.

https://cloudlogging.app.goo.gl/Yu321395kTNxZFiWA

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label May 10, 2024
Copy link

codecov bot commented May 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.37%. Comparing base (e0820a9) to head (24739ee).
Report is 184 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #70707       +/-   ##
===========================================
+ Coverage   50.46%   80.37%   +29.91%     
===========================================
  Files        6469     6517       +48     
  Lines      289328   298593     +9265     
  Branches    49888    52539     +2651     
===========================================
+ Hits       146002   239994    +93992     
+ Misses     142890    57865    -85025     
- Partials      436      734      +298     
Files Coverage Δ
src/sentry/models/files/abstractfile.py 93.97% <100.00%> (+68.57%) ⬆️

... and 2132 files with indirect coverage changes

@JoshFerge JoshFerge marked this pull request as ready for review May 13, 2024 17:12
@JoshFerge JoshFerge requested review from a team and asottile-sentry May 13, 2024 17:12
@JoshFerge
Copy link
Member Author

looking at this some more, the sockets are network based, not file based, so i don't think this PR is correct. looking further

@JoshFerge
Copy link
Member Author

@@ -107,6 +107,7 @@ def fetch_file(offset, getfile):
exe.submit(fetch_file, idx.offset, idx.blob.getfile)

mem.flush()
mem.close()
Copy link
Member

Choose a reason for hiding this comment

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

mmap supports the context manager protocol so I would recommend that instead

mmap also doesn't trigger a ResourceWarning when left unclosed (though arguably it should) so your warnings are definitely coming from somewhere else -- do you have some sample lines?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, i think its coming from the getfile function that is passed in (https://github.com/getsentry/getsentry/blob/056e9cc337b98984b37ffd3b40a79adea07c32e5/getsentry/filestore.py#L141 in prod)
and example warning is:

/usr/src/sentry/src/sentry/models/files/abstractfile.py:38: ResourceWarning: unclosed <socket.socket fd=179, family=2, type=1, proto=6, laddr=('10.4.161.44', 43014), raddr=('10.8.0.230', 11211)>
  self._prefetch(prefetch_to, delete)

@JoshFerge JoshFerge closed this May 14, 2024
@JoshFerge
Copy link
Member Author

@asottile-sentry
Copy link
Member

this should probably happen anyway -- right now that file descriptor is torn down at an undefined time

@JoshFerge JoshFerge reopened this May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants