fix #1170: Use ReentrantLock instead of Object monitors#1172
fix #1170: Use ReentrantLock instead of Object monitors#1172carterkozak wants to merge 2 commits intogoogle:masterfrom
Conversation
|
Thanks for this! I think you can actually go a bit further - |
|
I think ReadWriteLocks may be the right way to go here, but I'm not confident that I have enough context on what we're guarding to make the right call. For example Given this, I'd like to move forward initially with ReentrantLock because it should produce a semantically equivalent behavior, and should introduce less risk because the change is primarily structural. Moving from ReentrantLock to ReentrantReadWriteLock doesn't necessarily require structural changes, and could be handled later as an iterative step. Let me know if this sounds reasonable to you, thanks! |
1d04fd6 to
3dde52e
Compare
Makes sense... I remember now that I started looking into tidying up the state transitions in ConscryptEngine along the lines of #1120 and the realised it's a bigger project that I thought. So yeah, let's take things one step at a time. |
|
Looks like the ReadWrite locking in #490 and was done in isolation to address finalizer races (i.e. when
It's worse than that, it also seems to be used as a general purpose mutex around Better yet, references to Which is annoying because that means you'll have to keep ConscryptFileDescriptorSocket in this CL... I was going to suggest dropping it as it's beyond deprecated but we still have one major user, who are very change-averse. |
| sslLock.unlock(); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
provideAfterHandshakeSession() also needs locking (my bad!)
There was a problem hiding this comment.
Happy to fix it up. We may be able to add a compileOnly("com.google.errorprone:error_prone_annotations:$errorproneVersion") to take advantage of @GuardedBy checks without introducing a dependency for consumers.
There was a problem hiding this comment.
The exportKeyingMaterial is interesting because it locks over the state check, but not the NativeSsl interaction:
conscrypt/common/src/main/java/org/conscrypt/ConscryptEngine.java
Lines 1839 to 1849 in b14310d
Ah, great catch, thanks! I'll fix this up, and take another pass over other code which synchronizes on NativeSsl. |
This is not a complete implementation of #1170, but does address the primary areas where I've encountered virtual thread pinning in (non-exhaustive) tests. I realize this draft PR is premature as we haven't had a chance to discuss options on the issue yet -- I'd put this much together for some testing elsewhere, and thought I'd share it. No hard feelings if you'd prefer a different approach :-)
I suspect we may want to handle
ConscryptFileDescriptorSocketin addition to the defaultConscryptEngineSocketto avoid surprises, but I can certainly imagine an argument against updating the old (deprecated?) implementation.