-
Notifications
You must be signed in to change notification settings - Fork 68
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
Try to fix synchronization in SemaphoreStep
#258
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,13 +189,16 @@ public static class Execution extends AbstractStepExecutionImpl { | |
Object returnValue = null; | ||
Throwable error = null; | ||
boolean success = false, failure = false, sync = true; | ||
String c = Jenkins.XSTREAM.toXML(getContext()); | ||
synchronized (s) { | ||
if (s.returnValues.containsKey(k)) { | ||
success = true; | ||
returnValue = s.returnValues.get(k); | ||
} else if (s.errors.containsKey(k)) { | ||
failure = true; | ||
error = s.errors.get(k); | ||
} else { | ||
s.contexts.put(k, c); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the fix. Other threads now only ever see |
||
} | ||
} | ||
if (success) { | ||
|
@@ -206,10 +209,6 @@ public static class Execution extends AbstractStepExecutionImpl { | |
getContext().onFailure(error); | ||
} else { | ||
LOGGER.info(() -> "Blocking " + k); | ||
String c = Jenkins.XSTREAM.toXML(getContext()); | ||
synchronized (s) { | ||
s.contexts.put(k, c); | ||
} | ||
sync = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW I think there may be other pre-existing bugs here. What happens if another thread calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should change the overall approach, drop support for the synchronous completion cases, and have the step just poll continuously on a background thread looking for results. It would be slower and less efficient, but it also seems less prone to complex synchronization issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FWIW, I filed #259 with an example of what that could look like. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That would be normal if |
||
} | ||
synchronized (s) { | ||
|
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.
Just keeping this out of the synchronized block as before.