4343import java .nio .charset .StandardCharsets ;
4444import java .util .Enumeration ;
4545import java .util .Map ;
46+ import java .util .concurrent .atomic .AtomicBoolean ;
4647import java .util .concurrent .CompletionStage ;
4748import java .util .concurrent .CountDownLatch ;
4849import java .util .concurrent .TimeUnit ;
@@ -58,8 +59,6 @@ public abstract class AbstractHttpExecutor {
5859
5960 private static final Logger logger = LoggerFactory .getLogger (AbstractHttpExecutor .class );
6061
61- private volatile boolean isTimeout = false ;
62-
6362 /**
6463 * Http codec tool
6564 */
@@ -68,14 +67,15 @@ public abstract class AbstractHttpExecutor {
6867 protected void execute (HttpServletRequest request , HttpServletResponse response ,
6968 RpcMethodInfoAndInvoker methodInfoAndInvoker ) {
7069
70+ AtomicBoolean isTimeout = new AtomicBoolean (false );
7171 try {
7272
7373 DefRequest rpcRequest = buildDefRequest (request , response , methodInfoAndInvoker );
7474
7575 CountDownLatch countDownLatch = new CountDownLatch (1 );
7676
7777 // use a thread pool for asynchronous processing
78- invokeRpcRequest (methodInfoAndInvoker .getInvoker (), rpcRequest , countDownLatch );
78+ invokeRpcRequest (methodInfoAndInvoker .getInvoker (), rpcRequest , countDownLatch , isTimeout );
7979
8080 // If the request carries a timeout, use this timeout to wait for the request to be processed.
8181 // If not carried, use the default timeout.
@@ -84,7 +84,7 @@ protected void execute(HttpServletRequest request, HttpServletResponse response,
8484 requestTimeout = methodInfoAndInvoker .getInvoker ().getConfig ().getRequestTimeout ();
8585 }
8686 if (requestTimeout > 0 && !countDownLatch .await (requestTimeout , TimeUnit .MILLISECONDS )) {
87- isTimeout = true ;
87+ isTimeout . set ( true ) ;
8888 throw TRpcException .newFrameException (ErrorCode .TRPC_SERVER_TIMEOUT_ERR ,
8989 "wait http request execute timeout" );
9090 } else {
@@ -112,7 +112,8 @@ protected void execute(HttpServletRequest request, HttpServletResponse response,
112112 *
113113 * @param countDownLatch latch used to wait for the request processing
114114 */
115- private void invokeRpcRequest (ProviderInvoker <?> invoker , DefRequest rpcRequest , CountDownLatch countDownLatch ) {
115+ private void invokeRpcRequest (ProviderInvoker <?> invoker , DefRequest rpcRequest , CountDownLatch countDownLatch ,
116+ AtomicBoolean isTimeout ) {
116117
117118 WorkerPool workerPool = invoker .getConfig ().getWorkerPoolObj ();
118119
@@ -131,7 +132,7 @@ private void invokeRpcRequest(ProviderInvoker<?> invoker, DefRequest rpcRequest,
131132 CompletionStage <Response > future = invoker .invoke (rpcRequest );
132133 future .whenComplete ((result , t ) -> {
133134 try {
134- if (isTimeout ) {
135+ if (isTimeout . get () ) {
135136 return ;
136137 }
137138
0 commit comments