Skip to content

thread dead lock when use asyncresttmplate #2723

@jr981008

Description

@jr981008

when code like this:
` ListenableFuture<ResponseEntity> future = asyncRestTemplate.postForEntity("cse://xx/a/t",
new HttpEntity(""), String.class);
future.addCallback(new ListenableFutureCallback<ResponseEntity>() {
@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions