groupBy v2: Fix dangling references. (#3500)

Acquiring references in the processing task prevents dangling references
caused by canceled processing tasks.
This commit is contained in:
Gian Merlino 2016-09-23 13:29:11 -07:00 committed by Nishant
parent 9226d4af3c
commit 7195be32d8
1 changed files with 24 additions and 41 deletions

View File

@ -205,17 +205,16 @@ public class GroupByMergingQueryRunnerV2 implements QueryRunner
); );
} }
final Releaser bufferReleaser = mergeBufferHolder.increment();
try {
final Releaser grouperReleaser = grouperHolder.increment();
try {
return exec.submit( return exec.submit(
new AbstractPrioritizedCallable<Boolean>(priority) new AbstractPrioritizedCallable<Boolean>(priority)
{ {
@Override @Override
public Boolean call() throws Exception public Boolean call() throws Exception
{ {
try { try (
Releaser bufferReleaser = mergeBufferHolder.increment();
Releaser grouperReleaser = grouperHolder.increment()
) {
final Object retVal = input.run(queryForRunners, responseContext) final Object retVal = input.run(queryForRunners, responseContext)
.accumulate(grouper, accumulator); .accumulate(grouper, accumulator);
@ -229,26 +228,10 @@ public class GroupByMergingQueryRunnerV2 implements QueryRunner
log.error(e, "Exception with one of the sequences!"); log.error(e, "Exception with one of the sequences!");
throw Throwables.propagate(e); throw Throwables.propagate(e);
} }
finally {
grouperReleaser.close();
bufferReleaser.close();
}
} }
} }
); );
} }
catch (Exception e) {
// Exception caught while submitting the task; release resources.
grouperReleaser.close();
throw e;
}
}
catch (Exception e) {
// Exception caught while submitting the task; release resources.
bufferReleaser.close();
throw e;
}
}
} }
) )
) )