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

Commits on Jul 21, 2020

  1. Add caller stacktrace to rethrown RuntimeException

    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)
    sancar committed Jul 21, 2020
    Configuration menu
    Copy the full SHA
    2fcc329 View commit details
    Browse the repository at this point in the history
  2. test fixes

    (cherry picked from commit da89fba)
    sancar committed Jul 21, 2020
    Configuration menu
    Copy the full SHA
    3178356 View commit details
    Browse the repository at this point in the history