Repository: apache/dubbo
File: dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java (Java)

Code before:
                + timeout + " ms, request: " + (logger.isDebugEnabled() ? request : request.copyWithoutData())
                + ", channel: " + channel.getLocalAddress()
                + " -> " + channel.getRemoteAddress();
    }

    private static class TimeoutCheckTask implements TimerTask {

        private final Long requestID;

        TimeoutCheckTask(Long requestID) {
            this.requestID = requestID;
        }

        @Override
        public void run(Timeout timeout) {
            DefaultFuture future = DefaultFuture.getFuture(requestID);
            if (future == null || future.isDone()) {
                return;
            }
            ExecutorService executor = future.getExecutor();
            if (executor != null && !executor.isShutdown()) {
                try {
                    executor.execute(() -> notifyTimeout(future));
                } catch (RejectedExecutionException e) {
                    notifyTimeout(future);
                }
            } else {
                notifyTimeout(future);
            }
        }

        private void notifyTimeout(DefaultFuture future) {
            // create exception response.
            Response timeoutResponse = new Response(future.getId());
            // set timeout status.
            timeoutResponse.setStatus(future.isSent() ? Response.SERVER_TIMEOUT : Response.CLIENT_TIMEOUT);
            timeoutResponse.setErrorMessage(future.getTimeoutMessage(true));
            // handle response.
            DefaultFuture.received(future.getChannel(), timeoutResponse, true);
        }
    }
}


Review comment (suggestion):
I think it should throw an exception. Also, I think we need another PR to change it so that it does not call notifyTimeout, because it’s not actually a timeout.

Code after:
                + timeout + " ms, request: " + (logger.isDebugEnabled() ? request : request.copyWithoutData())
                + ", channel: " + channel.getLocalAddress()
                + " -> " + channel.getRemoteAddress();
    }

    private static class TimeoutCheckTask implements TimerTask {

        private final Long requestID;

        TimeoutCheckTask(Long requestID) {
            this.requestID = requestID;
        }

        @Override
        public void run(Timeout timeout) {
            DefaultFuture future = DefaultFuture.getFuture(requestID);
            if (future == null || future.isDone()) {
                return;
            }

            ExecutorService executor = future.getExecutor();
            if (executor != null && !executor.isShutdown()) {
                try {
                    executor.execute(() -> notifyTimeout(future));
                } catch (RejectedExecutionException e) {
                    notifyTimeout(future);
                    throw e;
                }
            } else {
                notifyTimeout(future);
            }
        }

        private void notifyTimeout(DefaultFuture future) {
            // create exception response.
            Response timeoutResponse = new Response(future.getId());
            // set timeout status.
            timeoutResponse.setStatus(future.isSent() ? Response.SERVER_TIMEOUT : Response.CLIENT_TIMEOUT);
            timeoutResponse.setErrorMessage(future.getTimeoutMessage(true));
            // handle response.
            DefaultFuture.received(future.getChannel(), timeoutResponse, true);
        }
    }
}