Fix Ratpack tests that got broken by ExecutorInstrumentation refactoring

It turns out closing continuation also closes parent span. This is not
very good in cases when we end up not using continuation if
continuation in a state has already been setup.

This patch provides way to close continuation in a way that doesn't
affect parent scope.
This commit is contained in:
Nikolay Martynov 2018-11-28 22:14:38 -08:00
parent 4ec5ca394c
commit 2e8dc9d08f
3 changed files with 25 additions and 3 deletions

View File

@ -66,6 +66,7 @@ public final class ExecutorInstrumentation extends Instrumenter.Default {
"scala.concurrent.impl.ExecutionContextImpl$$anon$3",
"akka.dispatch.MessageDispatcher",
"akka.dispatch.Dispatcher",
"akka.dispatch.Dispatcher$LazyExecutorServiceDelegate",
"akka.actor.ActorSystemImpl$$anon$1",
"akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinPool",
"akka.dispatch.forkjoin.ForkJoinPool",
@ -347,7 +348,7 @@ public final class ExecutorInstrumentation extends Instrumenter.Default {
if (state.setContinuation(continuation)) {
log.debug("created continuation {} from scope {}, state: {}", continuation, scope, state);
} else {
continuation.close();
continuation.close(false);
}
return state;
}

View File

@ -32,7 +32,19 @@ public interface TraceScope {
*/
TraceScope activate();
/** Cancel the continuation. */
/**
* Cancel the continuation. This also closes parent scope.
*
* <p>FIXME: the fact that this is closing parent scope is confusing, we should review this in
* new API.
*/
void close();
/**
* Close the continuation.
*
* @param closeContinuationScope true iff parent scope should also be closed
*/
void close(boolean closeContinuationScope);
}
}

View File

@ -128,9 +128,18 @@ public class ContinuableScope implements Scope, TraceScope {
@Override
public void close() {
close(true);
}
@Override
public void close(final boolean closeContinuationScope) {
if (used.compareAndSet(false, true)) {
trace.cancelContinuation(this);
ContinuableScope.this.close();
if (closeContinuationScope) {
ContinuableScope.this.close();
} else {
openCount.decrementAndGet();
}
} else {
log.debug("Failed to close continuation {}. Already used.", this);
}