-
Notifications
You must be signed in to change notification settings - Fork 1.9k
PredictionEnginePool.GetPredictionEngine is not thread safe #4981
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
Comments
Thanks for reporting this. Can you please provide your complete code and dataset so that we can easily reproduce your issue? Thanks! |
The attachment contains the source file and the model file. This problem occurs randomly and may take a long time to see. Thank you for your help |
Thanks. I am taking a look. Also, what kind of exception was thrown? It seems you only included the stacktrace on your description of the issue, but not the exception itself. |
It seems the way @eerhardt Is looking into this now to fix it. |
Accesses to this list are not thread-safe because we can be enumerating it on one thread (in Return) while another thread adds to it (in Create). The list is unnecessary because the PredictionEngine will always be "rooted". Either it was being held in memory by someone who got the PredictionEngine from the pool, or it is being held by the ObjectPool itself. So it won't ever be GC'd, and the WeakReference is not doing anything. Also, inherit from PooledObjectPolicy instead of IPooledObjectPolicy, so it can take the "fastPolicy" path in DefaultObjectPool. (See dotnet/extensions#318). Fix dotnet#4981
Accesses to this list are not thread-safe because we can be enumerating it on one thread (in Return) while another thread adds to it (in Create). The list is unnecessary because the PredictionEngine will always be "rooted". Either it was being held in memory by someone who got the PredictionEngine from the pool, or it is being held by the ObjectPool itself. So it won't ever be GC'd, and the WeakReference is not doing anything. Also, inherit from PooledObjectPolicy instead of IPooledObjectPolicy, so it can take the "fastPolicy" path in DefaultObjectPool. (See dotnet/extensions#318). Fix #4981
System information
Issue
Invoked PredictionEnginePool.Predict("MyModelName", example) from multiple threads.
Collection was modified; enumeration operation may not execute.
Method is thread safe
Source code / logs
Package
Microsoft.Azure.Functions.Extensions Version="1.0.0"
Microsoft.Extensions.MLVersion="1.5.0-preview2" or 1.40
Microsoft.ML Version="1.5.0-preview2" or 1.40
Microsoft.NET.Sdk.Functions Version="3.0.3"
in startup
builder.Services.AddPredictionEnginePool<Input, PredictedEngineOutput>().FromFile("ModelName", "ModelPath", true);
in function
var re = _PredictionEnginePool.Predict("ModelName", new Input() {String = str });
Exception
Please paste or attach the code or logs or traces that would be helpful to diagnose the issue you are reporting.
The text was updated successfully, but these errors were encountered: