-
Notifications
You must be signed in to change notification settings - Fork 278
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 #1170: Use ReentrantLock instead of Object monitors #1172
base: master
Are you sure you want to change the base?
fix #1170: Use ReentrantLock instead of Object monitors #1172
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. |
return state == STATE_HANDSHAKE_STARTED ? activeSession | ||
: SSLNullSession.getNullSession(); | ||
} finally { | ||
sslLock.unlock(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provideAfterHandshakeSession()
also needs locking (my bad!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
byte[] exportKeyingMaterial(String label, byte[] context, int length) throws SSLException { | |
sslLock.lock(); | |
try { | |
if (state < STATE_HANDSHAKE_COMPLETED || state == STATE_CLOSED) { | |
return null; | |
} | |
} finally { | |
sslLock.unlock(); | |
} | |
return ssl.exportKeyingMaterial(label, context, length); | |
} |
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
ConscryptFileDescriptorSocket
in addition to the defaultConscryptEngineSocket
to avoid surprises, but I can certainly imagine an argument against updating the old (deprecated?) implementation.