-
Notifications
You must be signed in to change notification settings - Fork 34
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
SmbTransport.ClearCachedConnections with force=true leads to InvalidOperationException #40
Comments
@ume05rw Do you think it would be possible to change this for the next version of SharpsCifs.Std? |
We just recently fixed this ourselves. Change this line -
to this: foreach (var transport in SmbConstants.Connections.ToArray()) |
@gcamp806 Thank you! My team is trying to figure out our next steps and whether we fork this ourselves or if we want to find another solution. |
@GoldenCave You're welcome! We decided to fork it and publish an internal NuGet package. There might be other viable solutions out there, but this one has worked well up until this edge case we encountered. The cost of rewriting / testing code to use another solution was more "expensive" than just publishing an internal package once. While doing that, we also added the updates in PR #39. |
Apply fix from ume05rw#40 (comment)
When calling SmbTransport.ClearCachedConnections (true) with force=true, we experienced an InvalidOperationException:
Here is the code: SmbTransport.ClearCachedConnections. The code enumerates over that collection (SmbConstants.Connections), and then tries to remove an element from it (with force=true), which gives it the InvalidOperationException. At least that is what stackoverflow suggests "You can't remove items from the same list you're using in the foreach, you'll get an exception (System.InvalidOperationException)."
Otherwise this other stack overflow suggests that the collection itself is modified by another thread, but the code above has a lock on the collection, so I think it is the one responsible stack overflow
So, it seems if we changed it to use an index-based for loop instead, we could get around this problem.
The text was updated successfully, but these errors were encountered: