servicecomb-java-chassis icon indicating copy to clipboard operation
servicecomb-java-chassis copied to clipboard

thread dead lock when use asyncresttmplate

Open jr981008 opened this issue 3 years ago • 1 comments

when code like this: ` ListenableFuture<ResponseEntity<String>> future = asyncRestTemplate.postForEntity("cse://xx/a/t", new HttpEntity<String>(""), String.class); future.addCallback(new ListenableFutureCallback<ResponseEntity<String>>() { @Override public void onFailure(Throwable e) { e.printStackTrace(); }

                     @Override
                     public void onSuccess(ResponseEntity<String> v) {
                         try{
                             System.out.println(restTemplate.getForObject("cse://xx/a/t1", String.class));
                         }catch (Throwable e){
                             e.printStackTrace();
                         }
                     }`

High probability(5% 100tps) vertx eventloop deadlock: stacktrace 2022-02-17 21:04:22 944[WARN][BlockedThreadChecker.java-63][vertx-blocked-thread-checker]-Thread Thread[vert.x-eventloop-thread-3,5,main]=Thread[vert.x-eventloop-thread-3,5,main] has been blocked for 202069 ms, time limit is 2000 ms io.vertx.core.VertxException: Thread blocked at sun.misc.Unsafe.park(Native Method) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836) at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997) at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304) at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231) at org.apache.servicecomb.core.provider.consumer.SyncResponseExecutor.waitResponse(SyncResponseExecutor.java:53) at org.apache.servicecomb.core.provider.consumer.InvokerUtils.innerSyncInvoke(InvokerUtils.java:86) at org.apache.servicecomb.provider.springmvc.reference.CseClientHttpRequest.doInvoke(CseClientHttpRequest.java:211) at org.apache.servicecomb.provider.springmvc.reference.CseClientHttpRequest.invoke(CseClientHttpRequest.java:201) at org.apache.servicecomb.provider.springmvc.reference.CseClientHttpRequest.execute(CseClientHttpRequest.java:152) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:737) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:672) at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:313)

check code: syncresttmplate use countdownlatch wait in 200 threadspool,but asyncresttemplate use vertx eventloop forcallback,so when useing a syncrequest in asycnrequest callback ,vertx may dispatch request or result in the same eventloop thread ,if happen,this thread will dead lock forever,not timeout and other way to recover. i dont see any warn about the way use like these.

jr981008 avatar Feb 18 '22 02:02 jr981008

使用异步的时候,不能在onSuccess逻辑里面使用同步调用。

liubao68 avatar Feb 18 '22 05:02 liubao68

close old issues, please feel free to submit a new one if the problem still exists.

liubao68 avatar Dec 30 '22 09:12 liubao68