-
Notifications
You must be signed in to change notification settings - Fork 306
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
[PAYARA-3860] - Added synchronization block double check to avoid race condition #4021
Conversation
Jenkins test please |
if (me == null) {//race check | ||
initialiseInstanceDescriptor(); | ||
//Race condition double check | ||
if (me == null) { |
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.
https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
https://www.javaworld.com/article/2074979/double-checked-locking--clever--but-broken.html
Page 348 of the book I'm about to plonk on your desk :)
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.
Oh, why did I miss that article? :)
Likely the easiest solution then is to replace any access to me
with synchronized getter that can also initialize the descriptor when null.
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.
Is something like
private synchronized InstanceDescriptorImpl getMyInstanceDescriptor() {
if(me == null) {
initialiseInstanceDescriptor();
}
return me;
}
the kind of thing you mean?
Jenkins test please |
@Inject | ||
private PayaraExecutorService executor; | ||
|
||
private synchronized InstanceDescriptorImpl getMyInstanceDescriptor() { | ||
if(me == null) { |
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.
space after if, please
@@ -239,50 +243,46 @@ void postConstruct() { | |||
@SuppressWarnings({"unchecked"}) | |||
public void event(Event event) { | |||
if (event.is(EventTypes.SERVER_READY)) { | |||
initialiseInstanceDescriptor(); | |||
PayaraInternalEvent pie = new PayaraInternalEvent(PayaraInternalEvent.MESSAGE.ADDED, me); | |||
//initialiseInstanceDescriptor(); |
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.
remove this one as well
Jenkins Test Please |
Added a synchronized double check in PayaraInstanceImpl to avoid race condition - tested through sheer brute forcing of Thread.sleep() and spamming of functionality and problem no longer appears to be present