@@ -73,8 +73,12 @@ protected void execute(HttpServletRequest request, HttpServletResponse response,
7373 try {
7474 DefRequest rpcRequest = buildDefRequest (request , response , methodInfoAndInvoker );
7575 CompletableFuture <Void > completionFuture = new CompletableFuture <>();
76+
7677 // use a thread pool for asynchronous processing
7778 invokeRpcRequest (methodInfoAndInvoker .getInvoker (), rpcRequest , completionFuture , responded );
79+
80+ // If the request carries a timeout, use this timeout to wait for the request to be processed.
81+ // If not carried, use the default timeout.
7882 long requestTimeout = rpcRequest .getMeta ().getTimeout ();
7983 if (requestTimeout <= 0 ) {
8084 requestTimeout = methodInfoAndInvoker .getInvoker ().getConfig ().getRequestTimeout ();
@@ -84,7 +88,8 @@ protected void execute(HttpServletRequest request, HttpServletResponse response,
8488 completionFuture .get (requestTimeout , TimeUnit .MILLISECONDS );
8589 } catch (TimeoutException ex ) {
8690 if (responded .compareAndSet (false , true )) {
87- sendTimeoutResponse (request , response );
91+ doErrorReply (request , response , TRpcException .newFrameException (ErrorCode .TRPC_SERVER_TIMEOUT_ERR ,
92+ "wait http request execute timeout" ));
8893 }
8994 }
9095 } else {
@@ -120,10 +125,10 @@ private void invokeRpcRequest(ProviderInvoker<?> invoker, DefRequest rpcRequest,
120125 AtomicBoolean responded ) {
121126
122127 WorkerPool workerPool = invoker .getConfig ().getWorkerPoolObj ();
123- if (workerPool == null ) {
124- logger .error ("Worker pool is not available" );
128+ if (null == workerPool ) {
129+ logger .error ("dispatch rpcRequest [{}] error, workerPool is empty" , rpcRequest );
125130 completionFuture .completeExceptionally (
126- TRpcException .newFrameException (ErrorCode .TRPC_SERVER_NOSERVICE_ERR , "Worker pool not available " )
131+ TRpcException .newFrameException (ErrorCode .TRPC_SERVER_NOSERVICE_ERR , "not found service, workerPool is empty " )
127132 );
128133 return ;
129134 }
@@ -183,20 +188,6 @@ private void handleError(Throwable t, DefRequest rpcRequest, HttpServletResponse
183188 }
184189 }
185190
186- /**
187- * Send timeout response
188- */
189- private void sendTimeoutResponse (HttpServletRequest request , HttpServletResponse response ) {
190- try {
191- response .setStatus (HttpStatus .SC_GATEWAY_TIMEOUT );
192- response .getWriter ().write ("Request Timeout" );
193- response .flushBuffer ();
194- logger .warn ("Request timeout: {} {}" , request .getMethod (), request .getRequestURI ());
195- } catch (IOException e ) {
196- logger .error ("Failed to send timeout response" , e );
197- }
198- }
199-
200191 /**
201192 * Build the context request.
202193 *
0 commit comments