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
Commits on Jul 21, 2020
-
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 committedJul 21, 2020 Configuration menu - View commit details
-
Copy full SHA for 2fcc329 - Browse repository at this point
Copy the full SHA 2fcc329View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3178356 - Browse repository at this point
Copy the full SHA 3178356View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.