Skip to content
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

Merged
merged 5 commits into from
Jun 11, 2019

Conversation

cubastanley
Copy link
Contributor

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

@cubastanley cubastanley changed the title Added synchronization block double check to avoid race condition [PAYARA-3860] - Added synchronization block double check to avoid race condition Jun 7, 2019
@cubastanley
Copy link
Contributor Author

Jenkins test please

if (me == null) {//race check
initialiseInstanceDescriptor();
//Race condition double check
if (me == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

Copy link
Contributor Author

@cubastanley cubastanley Jun 7, 2019

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?

@cubastanley cubastanley requested review from Pandrex247 and pdudits June 7, 2019 15:33
@cubastanley
Copy link
Contributor Author

Jenkins test please

@Inject
private PayaraExecutorService executor;

private synchronized InstanceDescriptorImpl getMyInstanceDescriptor() {
if(me == null) {
Copy link
Contributor

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();
Copy link
Contributor

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

@cubastanley
Copy link
Contributor Author

Jenkins Test Please

@cubastanley cubastanley merged commit 4ee9895 into payara:master Jun 11, 2019
@arjantijms arjantijms added this to the 5.193 milestone Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants