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 issue 5350, check file lock before reload model #5351

Merged
merged 2 commits into from
Aug 18, 2020

Conversation

frank-dong-ms-zz
Copy link
Contributor

fix issue #5350

The issue here is we use a file system watcher to watch model file change and reload the new model file automatically. The problem here is when we try to load the new model file this file is still locked thus cause the reload to fail.
Previously we are wait for 50 milliseconds before reload the new model file but that fails to work sometimes so here change the strategy to consistently check whether the file can be reload every 50 milliseconds for at most 100 times (which is roughly at total 5 seconds). If we still can't reload new model file after 5 seconds, throw IOException.

@codecov
Copy link

codecov bot commented Aug 18, 2020

Codecov Report

Merging #5351 into master will increase coverage by 0.00%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #5351   +/-   ##
=======================================
  Coverage   73.97%   73.97%           
=======================================
  Files        1019     1019           
  Lines      190005   190031   +26     
  Branches    20455    20455           
=======================================
+ Hits       140550   140580   +30     
+ Misses      43905    43903    -2     
+ Partials     5550     5548    -2     
Flag Coverage Δ
#Debug 73.97% <ø> (+<0.01%) ⬆️
#production 69.75% <ø> (+<0.01%) ⬆️
#test 87.65% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...c/Microsoft.ML.FastTree/Utils/ThreadTaskManager.cs 79.48% <0.00%> (-20.52%) ⬇️
test/Microsoft.ML.Tests/AnomalyDetectionTests.cs 99.29% <0.00%> (-0.71%) ⬇️
...soft.ML.Data/DataLoadSave/Text/TextLoaderCursor.cs 89.45% <0.00%> (+0.15%) ⬆️
src/Microsoft.ML.PCA/PcaTrainer.cs 81.87% <0.00%> (+0.16%) ⬆️
...soft.ML.Transforms/Text/WordEmbeddingsExtractor.cs 86.87% <0.00%> (+1.13%) ⬆️
src/Microsoft.ML.CpuMath/EigenUtils.cs 88.49% <0.00%> (+1.19%) ⬆️
....ML.AutoML/PipelineSuggesters/PipelineSuggester.cs 83.19% <0.00%> (+3.36%) ⬆️

@@ -105,13 +105,37 @@ public override ITransformer GetModel()
return _model;
}

public bool IsFileLocked(string filePath)
{
Copy link
Contributor

@harishsk harishsk Aug 18, 2020

Choose a reason for hiding this comment

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

This seems okay, but it is better to return the file handle directly instead of returning bool and trying to reopen the file.
See the second answer here for a better solution: https://stackoverflow.com/questions/50744/wait-until-file-is-unlocked-in-net
#Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated.

Thread.Sleep(50);
using (var fileStream = File.OpenRead(_filePath))
var fs = WaitForFile(_filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
if (fs == null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you have a repro for this issue, can you please check it in as a test for this bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no easy way to test this, this repro requires to write a web api and call webapi in certain order and then check the output. We need to introduce some web test framework to do this.

Copy link
Member

Choose a reason for hiding this comment

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

You don't need a web test to use Microsoft.Extensions.ML. You can use it from any test project. We already have some tests here:

https://github.com/dotnet/machinelearning/tree/master/test/Microsoft.Extensions.ML.Tests

Copy link
Contributor

Choose a reason for hiding this comment

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

@eerhardt Thanks for the pointer. @frank-dong-ms Can you please add a test for this issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, thanks Eric, will do that in separate PR.

@frank-dong-ms-zz frank-dong-ms-zz merged commit 8413213 into dotnet:master Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Mar 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants