Skip to content

Commit

Permalink
MID-9162 MID-6607 ninja hangs on some occasions fix. Not very clean, …
Browse files Browse the repository at this point in the history
…but we're too close to release. Will be followed with another jira to cleanup this code.

(cherry picked from commit 67ec500)
  • Loading branch information
1azyman committed Oct 4, 2023
1 parent 242814c commit 0323216
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public AbstractWriterConsumerWorker(NinjaContext context,
public void run() {
Log log = context.getLog();

init();

Writer writer = null;
try {
init();

writer = createWriter();

while (!shouldConsumerStop()) {
Expand All @@ -63,8 +63,12 @@ public void run() {
finalizeWriter(writer);
} catch (IOException ex) {
log.error("Unexpected exception, reason: {}", ex, ex.getMessage());

operation.finish();
} catch (NinjaException ex) {
log.error(ex.getMessage(), ex);

operation.finish();
} finally {
if (options.getOutput() != null) {
// we don't want to close stdout, e.g. only if we were writing to file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ public EventResult preMarshall(Element objectElement, Node postValidationTree,
public EventResult postMarshall(
T object, Element objectElement, OperationResult objectResult) {
try {
if (operation.isFinished()) {
return EventResult.stop("Operation already finished");
}

if (filter != null) {
boolean match = ObjectQuery.match(object, filter, matchingRuleRegistry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public void run() {
operation.incrementError();
}
}
} catch (Exception ex) {
operation.finish();

throw ex;
} finally {
markDone();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public void run() {

ResultHandler<?> handler = (object, parentResult) -> {
try {
if (operation.isFinished()) {
return false;
}

queue.put(object.asObjectable());
} catch (InterruptedException ex) {
log.error("Couldn't queue object {}, reason: {}", ex, object, ex.getMessage());
Expand Down

0 comments on commit 0323216

Please sign in to comment.