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

make _CACHE thread-safe #123

Merged
merged 3 commits into from
May 6, 2022
Merged

make _CACHE thread-safe #123

merged 3 commits into from
May 6, 2022

Conversation

cossio
Copy link

@cossio cossio commented Apr 21, 2022

The global variable _CACHE is not thread-safe. This PR should fix that.

@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #123 (e208d35) into master (30ba13a) will increase coverage by 0.84%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #123      +/-   ##
==========================================
+ Coverage   96.87%   97.71%   +0.84%     
==========================================
  Files           6        6              
  Lines         224      219       -5     
==========================================
- Hits          217      214       -3     
+ Misses          7        5       -2     
Impacted Files Coverage Δ
src/metadata.jl 100.00% <100.00%> (ø)
src/upgrade.jl 100.00% <0.00%> (ø)
src/file_io.jl 94.44% <0.00%> (+1.46%) ⬆️
src/JLSOFile.jl 93.33% <0.00%> (+3.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30ba13a...e208d35. Read the comment docs.

Copy link
Member

@rofinn rofinn left a comment

Choose a reason for hiding this comment

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

LGTM, though I think a failing multi-threaded test would be a good idea...

global _CACHE[:PKGS][pkg] = ver
lock(_CACHE_LOCK) do
if isempty(_CACHE[:PKGS])
for (pkg, ver) in Pkg.installed()
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I think we should have a failing test cases that's fixed by this change? I wonder if we should mock the Pkg.installed() call in order to write an initially failing test for the non-threadsafe version? @oxinabox Do you have any opinions/suggestions on this?

Copy link
Author

Choose a reason for hiding this comment

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

I agree a test would nice. But I'm not sure how to write one in this case.

Copy link
Member

Choose a reason for hiding this comment

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

I can't think how to do this reliably.
Because the scheduler never promises to run things concurrently

@rofinn rofinn requested a review from oxinabox April 21, 2022 19:39
@oxinabox
Copy link
Member

LGTM, though I think a failing multi-threaded test would be a good idea...

Race conditions are basically impossible to unit test.

So I do not think this is required.

@cossio
Copy link
Author

cossio commented Apr 23, 2022

@oxinabox @rofinn Should be ready to merge?

@cossio
Copy link
Author

cossio commented Apr 25, 2022

Bump :)

@cossio cossio requested review from rofinn and oxinabox April 26, 2022 13:57
@oxinabox oxinabox merged commit 6884e37 into invenia:master May 6, 2022
@cossio
Copy link
Author

cossio commented May 6, 2022

Thanks!

@cossio cossio deleted the lock branch May 6, 2022 11:28
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.

3 participants