question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to check a request is timed out before executing a blocking task

See original GitHub issue

Some users want to reject to run a blocking task after a request was timed out. It seems useful to add an option that fails fast when a request was timed out when building a Server

class ServerBuilder {

    public ServerBuilder blockingTaskExecutor(int numThreads, boolean allowExecutingAfterTimeout) {
        if (!allowExecutingAfterTimeout) {
            BlockingTaskExecutor executor = 
                    BlockingTaskExecutor.builder()
                                        .numThreads(numThreads)
                                        .taskFunction(task -> {
                                            return () -> {
                                                 ServiceRequestContext ctx = ServiceRequestContext.currentOrNull();
                                                 if (ctx == null || !ctx.isTimedOut()) {
                                                    task.run();
                                                 }
                                            };
                                        })
                                        .build();
        } else {
            ...
        }
    }

}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
jupinycommented, Nov 18, 2021

Let me try it 😄 @ikhoon nim.

1reaction
ikhooncommented, Nov 18, 2021

Had a chat with @minwoox and he was concerned that a resource could be leaked if a close() method that should be called is not executed in the task job when taskFunction is used. Alternately, we can wrap a blocking task executor with a decorator.

class TimeoutAwareBlockingTaskExecutor implements BlockingTaskExecutor {
    private final ScheduledExecutorService delegate;

    @Override
    public void execute(Runnable command) {
         ServiceRequestContext ctx = ServiceRequestContext.currentOrNull();
         if (ctx == null || !ctx.isTimedOut()) {
            delegate.execute(command);
         } else {
            throw new RejectedExecutionException("Request has been timed out. ctx: " + ctx);
         }
    }
}

But I wasn’t sure that this is a good first issue. Because we need to check overall implementations that use BlockingTaskExecutor in Armeria. Why don’t you pick up another issue? 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

Receiving "The request timed out." when using NSURLSession
I'm facing a very strange problem in my application. In particular, using the application when a request receives a timeout message, all the...
Read more >
Asynchronously wait for Task<T> to complete with timeout
I can use Task. Wait to synchronously wait for the task to complete with a timeout, but that blocks my thread.
Read more >
Troubleshoot query time-out errors - SQL Server
This article describes how to troubleshoot the time-out errors when you run slow-running queries.
Read more >
Handling long Web Requests with Asynchronous Request ...
Long requests can time out the Web server Web servers are set up with certain timeouts to kill connections after the timeout period...
Read more >
Troubleshoot Lambda function invocation timeout errors
Retrieve the request IDs of any timed-out invocations by searching the function's Amazon CloudWatch log group for the phrase, Task timed out ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found