prestodb/presto · error · QueryPreprocessorException

Timed out waiting for query preprocessor after

Error message

Timed out waiting for query preprocessor after 

What it means

QueryPreprocessorException thrown when the preprocessor task does not complete within the configured timeout (Future.get(timeout)). On timeout the library also destroys the preprocessor process forcibly in the finally block. The message includes the elapsed timeout value that was exceeded.

Source

Thrown at presto-cli/src/main/java/com/facebook/presto/cli/QueryPreprocessor.java:193

                        errorMessage.map(message1 -> "\n===\n" + message1 + "\n===").orElse(""));
            }
            return result;
        });

        try {
            return task.get(timeout.toMillis(), MILLISECONDS);
        }
        catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new QueryPreprocessorException("Interrupted while preprocessing query");
        }
        catch (ExecutionException e) {
            Throwable cause = e.getCause();
            propagateIfPossible(cause, QueryPreprocessorException.class);
            throw new QueryPreprocessorException("Error preprocessing query: " + cause.getMessage(), cause);
        }
        catch (TimeoutException e) {
            throw new QueryPreprocessorException("Timed out waiting for query preprocessor after " + timeout);
        }
        finally {
            Process process = processReference.get();
            if (process != null) {
                process.destroyForcibly();
            }
            task.cancel(true);
        }
    }

    private static <T> Future<T> executeInNewThread(String threadName, Callable<T> callable)
    {
        FutureTask<T> task = new FutureTask<>(callable);
        Thread thread = new Thread(task);
        thread.setName(threadName);
        thread.setDaemon(true);
        thread.start();
        return task;

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Increase the preprocessor timeout so slow scripts can finish.
  2. Profile/speed up the preprocessor; make it stateless and fast.
  3. Check the script for blocking reads (stdin waits, network calls) and remove them.
  4. Test the preprocessor with representative query sizes to measure realistic runtime.
  5. If the preprocessor hangs intermittently, add its own internal timeout/failsafe exit.

Example fix

// before
./presto --server ... --preprocessor-command ./slow-preprocessor.sh   # hangs > timeout
// after
timeout 5 ./slow-preprocessor.sh  # self-limiting; also raise CLI preprocessor timeout
Defensive patterns

Strategy: try-catch

Validate before calling

# bound the preprocessor's own runtime
timeout 10s your-preprocessor.sh < sample.sql && echo OK

Try / catch

try {
    preprocessQuery(query);
} catch (QueryPreprocessorException e) {
    if (e.getMessage().startsWith("Timed out waiting for query preprocessor")) {
        log.error("preprocessor exceeded timeout; increase timeout or speed up the command");
    }
    throw e;
}

Prevention

When it happens

Trigger: The external --preprocessor-command process hangs or takes longer than the preprocessor timeout while rewriting a query, so task.get(timeout.toMillis(), MILLISECONDS) throws TimeoutException.

Common situations: Preprocessor script waits on stdin/network that never arrives; slow preprocessor (cold start, large queries) exceeding the timeout; deadlock in the preprocessor reading/writing streams.

Understand the failure class

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/65a258d27fd41819. Report an issue: GitHub.