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

Add caller stacktrace to rethrown RuntimeException #17249

Merged
merged 2 commits into from Jul 23, 2020

Conversation

sancar
Copy link
Contributor

@sancar sancar commented Jul 21, 2020

backport of #17212

fixes #17202

sancar added 2 commits July 21, 2020 10:22
We have lots of places that we use the following pattern
```
try {
     invocationFuture.get()
}catch(Exception e){
    throw retrhow(e);
}
```

If the exception is RuntimeException, it is not wrapped and thrown directly. In that case, we can not follow where the exception is thrown from. Here is an example of a put from a member.

```
java.lang.RuntimeException: here comes the bug
        at com.hazelcast.map.impl.operation.PutOperation.runInternal(PutOperation.java:36)
        at com.hazelcast.map.impl.operation.MapOperation.run(MapOperation.java:112)
        at com.hazelcast.spi.impl.operationservice.Operation.call(Operation.java:184)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:227)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:216)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:422)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:166)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:136)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.executeRun(OperationThread.java:123)
        at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
```

:
```
try {
     invocationFuture.get()
}catch(Exception e){
    throw retrhow(e);
}
```

If the exception is RuntimeException, it is not wrapped and thrown directly. In that case, we can not follow where the exception is thrown from. Here is an example of a put from a member.

```
java.lang.RuntimeException: here comes the bug
        at com.hazelcast.map.impl.operation.PutOperation.runInternal(PutOperation.java:36)
        at com.hazelcast.map.impl.operation.MapOperation.run(MapOperation.java:112)
        at com.hazelcast.spi.impl.operationservice.Operation.call(Operation.java:184)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:227)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:216)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:422)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:166)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:136)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.executeRun(OperationThread.java:123)
        at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
```

Same problem on the client side:

```
java.lang.RuntimeException: here comes the bug
        at com.hazelcast.map.impl.operation.PutOperation.runInternal(PutOperation.java:36)
        at com.hazelcast.map.impl.operation.MapOperation.run(MapOperation.java:112)
        at com.hazelcast.spi.impl.operationservice.Operation.call(Operation.java:184)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:227)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:216)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl.run(OperationExecutorImpl.java:411)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl.runOrExecute(OperationExecutorImpl.java:438)
        at com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvokeLocal(Invocation.java:597)
        at com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvoke(Invocation.java:582)
        at com.hazelcast.spi.impl.operationservice.impl.Invocation.invoke0(Invocation.java:541)
        at com.hazelcast.spi.impl.operationservice.impl.Invocation.invoke(Invocation.java:238)
        at com.hazelcast.spi.impl.operationservice.impl.InvocationBuilderImpl.invoke(InvocationBuilderImpl.java:59)
        at com.hazelcast.client.impl.protocol.task.AbstractPartitionMessageTask.processInternal(AbstractPartitionMessageTask.java:51)
        at com.hazelcast.client.impl.protocol.task.AbstractAsyncMessageTask.processMessage(AbstractAsyncMessageTask.java:71)
        at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:153)
        at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:116)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:180)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:172)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:140)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.executeRun(OperationThread.java:123)
        at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
```

These exceptions should contain the stack trace of the caller as well. But they only have the remote stack trace.

To fix this, the tryWrapInSameClass is moved to ExceptionUtil to be used by rethrow. AbstractInvocationFuture uses methods
from the ExceptionUtil.

After the fix, the stacktrace of the same run for the member:

```
java.lang.RuntimeException: here comes the bug
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
        at com.hazelcast.internal.util.ExceptionUtil.tryWrapInSameClass(ExceptionUtil.java:233)
        at com.hazelcast.internal.util.ExceptionUtil.wrapException(ExceptionUtil.java:138)
        at com.hazelcast.internal.util.ExceptionUtil.peel(ExceptionUtil.java:114)
        at com.hazelcast.internal.util.ExceptionUtil.peel(ExceptionUtil.java:120)
        at com.hazelcast.internal.util.ExceptionUtil.peel(ExceptionUtil.java:73)
        at com.hazelcast.internal.util.ExceptionUtil.rethrow(ExceptionUtil.java:148)
        at com.hazelcast.map.impl.proxy.MapProxySupport.invokeOperation(MapProxySupport.java:484)
        at com.hazelcast.map.impl.proxy.MapProxySupport.putInternal(MapProxySupport.java:411)
        at com.hazelcast.map.impl.proxy.MapProxyImpl.put(MapProxyImpl.java:130)
        at com.hazelcast.map.impl.proxy.MapProxyImpl.put(MapProxyImpl.java:120)
        at XNode.onliteMember(XNode.java:28)
        at XNode.main(XNode.java:14)
Caused by: java.lang.RuntimeException: here comes the bug
        at com.hazelcast.map.impl.operation.PutOperation.runInternal(PutOperation.java:36)
        at com.hazelcast.map.impl.operation.MapOperation.run(MapOperation.java:112)
        at com.hazelcast.spi.impl.operationservice.Operation.call(Operation.java:184)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:227)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:216)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:422)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:166)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:136)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.executeRun(OperationThread.java:123)
        at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
```

And the stacktrace of the same run for the client:

```
java.lang.RuntimeException: here comes the bug
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
        at com.hazelcast.internal.util.ExceptionUtil.tryWrapInSameClass(ExceptionUtil.java:233)
        at com.hazelcast.internal.util.ExceptionUtil.wrapException(ExceptionUtil.java:138)
        at com.hazelcast.internal.util.ExceptionUtil.peel(ExceptionUtil.java:114)
        at com.hazelcast.internal.util.ExceptionUtil.peel(ExceptionUtil.java:120)
        at com.hazelcast.internal.util.ExceptionUtil.peel(ExceptionUtil.java:73)
        at com.hazelcast.internal.util.ExceptionUtil.rethrow(ExceptionUtil.java:148)
        at com.hazelcast.client.impl.spi.ClientProxy.invokeOnPartition(ClientProxy.java:190)
        at com.hazelcast.client.impl.spi.ClientProxy.invoke(ClientProxy.java:182)
        at com.hazelcast.client.impl.proxy.ClientMapProxy.putInternal(ClientMapProxy.java:529)
        at com.hazelcast.client.impl.proxy.ClientMapProxy.put(ClientMapProxy.java:261)
        at XNode.onClient(XNode.java:41)
        at XNode.main(XNode.java:15)
Caused by: java.lang.RuntimeException: here comes the bug
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
        at com.hazelcast.internal.util.ExceptionUtil.tryWrapInSameClass(ExceptionUtil.java:233)
        at com.hazelcast.internal.util.ExceptionUtil.wrapException(ExceptionUtil.java:138)
        at com.hazelcast.internal.util.ExceptionUtil.peel(ExceptionUtil.java:114)
        at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.peelIfNeeded(AbstractMessageTask.java:348)
        at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.encodeException(AbstractMessageTask.java:275)
        at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.sendClientMessage(AbstractMessageTask.java:269)
        at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.handleProcessingFailure(AbstractMessageTask.java:194)
        at com.hazelcast.client.impl.protocol.task.AbstractAsyncMessageTask.sendResponseOrHandleFailure(AbstractAsyncMessageTask.java:84)
        at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:774)
        at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750)
        at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:456)
        at com.hazelcast.internal.util.ConcurrencyUtil$1.execute(ConcurrencyUtil.java:39)
        at java.util.concurrent.CompletableFuture$UniCompletion.claim(CompletableFuture.java:543)
        at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:765)
        at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750)
        at java.util.concurrent.CompletableFuture.uniWhenCompleteStage(CompletableFuture.java:795)
        at java.util.concurrent.CompletableFuture.whenCompleteAsync(CompletableFuture.java:2163)
        at com.hazelcast.client.impl.protocol.task.AbstractAsyncMessageTask.processMessage(AbstractAsyncMessageTask.java:73)
        at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:153)
        at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:116)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:180)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:172)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:140)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.executeRun(OperationThread.java:123)
        at com.hazelcast.internal.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:102)
Caused by: java.lang.RuntimeException: here comes the bug
        at com.hazelcast.map.impl.operation.PutOperation.runInternal(PutOperation.java:36)
        at com.hazelcast.map.impl.operation.MapOperation.run(MapOperation.java:112)
        at com.hazelcast.spi.impl.operationservice.Operation.call(Operation.java:184)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:227)
        at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:216)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl.run(OperationExecutorImpl.java:411)
        at com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl.runOrExecute(OperationExecutorImpl.java:438)
        at com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvokeLocal(Invocation.java:597)
        at com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvoke(Invocation.java:582)
        at com.hazelcast.spi.impl.operationservice.impl.Invocation.invoke0(Invocation.java:541)
        at com.hazelcast.spi.impl.operationservice.impl.Invocation.invoke(Invocation.java:238)
        at com.hazelcast.spi.impl.operationservice.impl.InvocationBuilderImpl.invoke(InvocationBuilderImpl.java:59)
        at com.hazelcast.client.impl.protocol.task.AbstractPartitionMessageTask.processInternal(AbstractPartitionMessageTask.java:51)
        at com.hazelcast.client.impl.protocol.task.AbstractAsyncMessageTask.processMessage(AbstractAsyncMessageTask.java:71)
        ... 7 more
```

fixes hazelcast#17202

(cherry picked from commit 5b225d0)
(cherry picked from commit da89fba)
@sancar sancar added this to the 4.0.3 milestone Jul 21, 2020
@sancar sancar requested a review from a team as a code owner July 21, 2020 07:24
@sancar sancar self-assigned this Jul 21, 2020
@puzpuzpuz puzpuzpuz self-requested a review July 22, 2020 07:27
@sancar sancar merged commit 318b336 into hazelcast:4.0.z Jul 23, 2020
@sancar sancar deleted the fix/callerStacktrace/4.0.z branch July 23, 2020 13:47
@mmedenjak mmedenjak added the Source: Internal PR or issue was opened by an employee label Aug 4, 2020
mmedenjak added a commit to mmedenjak/hazelcast that referenced this pull request Sep 11, 2020
…#17249)"

This reverts commit 318b336. Reasoning is that it introduces
significant changes in the invocation handling and causes some tests to
start failing. An alternate or augmented solution must be considered.
mmedenjak added a commit that referenced this pull request Sep 14, 2020
Revert "Add caller stacktrace to rethrown RuntimeException (#17249)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants