Skip to content

tests: garbage collect sqlite connections on Windows + Python 3.11 #8547

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 1 commit into from
Nov 16, 2022

Conversation

skshetry
Copy link
Collaborator

@skshetry skshetry commented Nov 10, 2022

There seems to be a regression in Python 3.11, where the sqlite
connections are not deallocated, due to some internal changes in
Python 3.11, where they are now using LRU cache. They are not deallocated
until gc.collect() is called.

See python/cpython#97641.
This affects only Windows, because when we try to remove the tempdir for
the exp run, the sqlite connection is open which prevents us from
deleting that folder.

Although this may happen in real scenario in exp run, I am only fixing
the tests by mocking dvc.close() and extending it by calling
gc.collect() after it. We could also mock State.close() but didnot
want to mock something that is not in dvc itself.

The diskcache uses threadlocal for connections, so they are expected
to be garbage collected, and therefore does not provide a good way to
close the connections. The only API it offers is self.close() and that
only closes main thread's connection. If we had access to connection,
an easier way would have been to explicitly call conn.close().
But we don''t have such option at the moment.

Related: #8404 (comment)
GHA Failure: https://github.com/iterative/dvc/actions/runs/3437324559/jobs/5731929385#step:5:57

@skshetry

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Nov 10, 2022

Codecov Report

Base: 94.31% // Head: 45.65% // Decreases project coverage by -48.66% ⚠️

Coverage data is based on head (150bd35) compared to base (fa54c1a).
Patch has no changes to coverable lines.

❗ Current head 150bd35 differs from pull request most recent head 288a23a. Consider uploading reports for the commit 288a23a to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #8547       +/-   ##
===========================================
- Coverage   94.31%   45.65%   -48.67%     
===========================================
  Files         430      430               
  Lines       32830    32840       +10     
  Branches     4581     4585        +4     
===========================================
- Hits        30963    14992    -15971     
- Misses       1449    17287    +15838     
- Partials      418      561      +143     
Impacted Files Coverage Δ
dvc/repo/params/diff.py 0.00% <0.00%> (-100.00%) ⬇️
dvc/repo/metrics/diff.py 0.00% <0.00%> (-100.00%) ⬇️
dvc/machine/backend/base.py 0.00% <0.00%> (-95.66%) ⬇️
tests/unit/stage/test_cache.py 7.75% <0.00%> (-92.25%) ⬇️
dvc/dagascii.py 0.00% <0.00%> (-91.37%) ⬇️
tests/integration/plots/conftest.py 8.92% <0.00%> (-91.08%) ⬇️
tests/func/test_update.py 10.15% <0.00%> (-89.85%) ⬇️
tests/unit/fs/test_dvc.py 10.33% <0.00%> (-89.67%) ⬇️
tests/integration/plots/test_repo_plots_api.py 10.52% <0.00%> (-89.48%) ⬇️
tests/func/test_run_cache.py 11.01% <0.00%> (-88.99%) ⬇️
... and 337 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@skshetry skshetry changed the title Test windows tests: garbage collect sqlite connections on Windows + Python 3.11 Nov 10, 2022
@skshetry skshetry added the skip-changelog Skips changelog label Nov 10, 2022
@skshetry skshetry marked this pull request as ready for review November 10, 2022 17:02
There seems to be a regression in Python 3.11, where the sqlite
connections are not deallocated, due to some internal changes in
Python 3.11, where they are now using LRU cache. They are not deallocated
until `gc.collect()` is not called.

See python/cpython#97641.
This affects only Windows, because when we try to remove the tempdir for
the exp run, the sqlite connection is open which prevents us from
deleting that folder.

Although this may happen in real scenario in `exp run`, I am only fixing
the tests by mocking `dvc.close()` and extending it by calling
`gc.collect()` after it. We could also mock `State.close()` but didnot
want to mock something that is not in dvc itself.

The `diskcache` uses threadlocal for connections, so they are expected
to be garbage collected, and therefore does not provide a good way to
close the connections. The only API it offers is `self.close()` and that
only closes main thread's connection. If we had access to connection,
an easier way would have been to explicitly call `conn.close()`.
But we don''t have such option at the moment.

Related: iterative#8404 (comment)
GHA Failure: https://github.com/iterative/dvc/actions/runs/3437324559/jobs/5731929385#step:5:57
@skshetry

This comment was marked as outdated.

@skshetry skshetry closed this Nov 11, 2022
@skshetry skshetry reopened this Nov 11, 2022
@pmrowla
Copy link
Contributor

pmrowla commented Nov 11, 2022

Seems like this will be required until the underlying python bug is fixed (windows tests are still flaky) https://github.com/iterative/dvc/actions/runs/3442517841/jobs/5743178770

@skshetry
Copy link
Collaborator Author

@pmrowla, what do you think of skipping deletion of temporary workspace on failures?

@pmrowla
Copy link
Contributor

pmrowla commented Nov 11, 2022

@pmrowla, what do you think of skipping deletion of temporary workspace on failures?

We've considered that in the past, but the end result was that users would just generate a ton of (failed) temp workspace copies without realizing they needed to run some additional command to clean them up afterwards.

@skshetry skshetry merged commit 65f61ac into iterative:main Nov 16, 2022
@skshetry skshetry deleted the test-windows branch November 16, 2022 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog Skips changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants