-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Make PhysicalBridge? physical member threadSafe #2966
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
base: main
Are you sure you want to change the base?
Make PhysicalBridge? physical member threadSafe #2966
Conversation
I'm going to have to take a careful look here. Ultimately, we're not changing this value randomly - it is set once, and under once; we could probably just remove the volatile entirely. I will need to read this one with much coffee to see what is going on. |
Just noting here that we can't take this route - it adds a ton of locking in a critical path :) |
Yes sure, this PR is a proof of concept to point the problem on the volatile physical connection class member For some cases i've locked a big portion of code to test this quicker, but we certainly can lock more precisely small portions, like for example in the TryEnqueue, i've locked the full loop on messages, we can lock only into the loop and check on each message if connection is available... |
"so easily corrupted" That's what I'd want to focus in on here; until we have a viable description of a code-path that somehow corrupts/confuses this value, this is just arbitrary code addition. |
I'll try to find this |
…utdown, =null ...) => so in normal run, only read locks are done => no slowdown out of connections problems because of read lock are reentrant
First try to find code path seem to point on connection management. By relaunching my memory test, for now each time i reproduce the issue, we have traces indicating that connection is recreated, on sometime multiple recreations are done ![]() other example ![]() I will dig more tomorrow to see if i can add more informations in logs. @mgravell Can you explain us how we can activate Traces / debug traces from StackExchange.Redis and where to see them ? i've tryed to add the VERBOSE build flag, but not see any trace :-( |
@jcaspes I appreciate the notion to benchmark as that is the right call, but I want to be up front: those call numbers are extremely small. We have folks operating at 1000x that load (where locking matters way more), and this adds performance overhead for sure. I'm not saying we don't have something to improve here, but adding an expensive lock around every call is not going to be the answer :) |
By reading PhysicalBridge code i see that the phycical connexion is hosted by a volatile class member to be "protected".
This have been done to securize concurrent accesses to the physical connection because of volatile keyword i think.. but iot's not really safe.
This PR try to move physical connection in a threadSafe accessor class so no conflicts can happen.
Some details:
Seeing this kind of unsafe codes:


or another example
and more example where we only test the nullity of the memeber and then work on it... but can be set to null, and /or shutdown / disposed at any time by an other thread
And reading the microsoft documentation for the volatile keyword here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile?devlangs=csharp

This code protection + HighIntegrity mode seem to fix the two issue: #2919 and #2920