apache/pulsar · error · RestException

Request Timed Out

Error message

Request Timed Out

What it means

After publishing the test message, triggerFunction polls the output topic with a Reader until System.currentTimeMillis() exceeds the request's deadline; if no matching message arrives in time it returns HTTP 408 Request Timeout 'Request Timed Out'. The function may still have executed — only result delivery timed out.

Source

Thrown at pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java:1218

            while (curTime < maxTime) {
                Message<?> msg = reader.readNext(10000, TimeUnit.MILLISECONDS);
                if (msg == null) {
                    break;
                }
                if (msg.getProperties().containsKey("__pfn_input_msg_id__")
                        && msg.getProperties().containsKey("__pfn_input_topic__")) {
                    MessageId newMsgId = MessageId.fromByteArray(
                            Base64.getDecoder().decode((String) msg.getProperties().get("__pfn_input_msg_id__")));

                    if (msgId.equals(newMsgId)
                            && msg.getProperties().get("__pfn_input_topic__")
                            .equals(TopicName.get(inputTopicToWrite).toString())) {
                        return new String(msg.getData());
                    }
                }
                curTime = System.currentTimeMillis();
            }
            throw new RestException(Status.REQUEST_TIMEOUT, "Request Timed Out");
        } catch (SchemaSerializationException e) {
            throw new RestException(Status.BAD_REQUEST, String.format(
                    "Failed to serialize input with error: %s. Please check"
                            + "if input data conforms with the schema of the input topic.",
                    e.getMessage()));
        } catch (IOException e) {
            throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
        } finally {
            if (reader != null) {
                reader.closeAsync();
            }
            if (producer != null) {
                producer.closeAsync();
            }
        }
    }

    @Override

View on GitHub (pinned to 820761864e)

Solutions

  1. Retry the trigger — first-invocation warm-up often makes the second attempt succeed.
  2. Increase the client/HTTP read timeout for the trigger request so the worker's polling window isn't cut short.
  3. Inspect function logs and the output topic with a consumer to confirm whether output was actually produced.
  4. Reduce function startup cost or input backlog so processing fits the timeout window.

Example fix

// before: default curl timeout too short
curl -X POST --data-binary 'x' .../functions/.../f?topic=src
// after
curl -m 120 -X POST --data-binary 'x' .../functions/.../f?topic=src
Defensive patterns

Strategy: retry

Validate before calling

// Choose a client read timeout comfortably above expected processing time
int readTimeoutMs = Math.max(functionMaxProcessingMs * 2, 120_000);

Try / catch

for (int i = 0; i < 3; i++) {
  try { return triggerWithTimeout(...); }
  catch (PulsarAdminException e) {
    if (e.getResponseStatus() == 408) { backoff(i); continue; }
    throw e;
  }
}
throw new TimeoutException("trigger did not return within retries");

Prevention

When it happens

Trigger: Function takes longer than the timeout window to process and publish its output; output topic differs or the result message doesn't match the expected input topic context; the function failed silently and never produced output; consumer fell behind.

Common situations: Functions with slow initialization (first invocation loads models/connections) exceeding the window; high backlog on the output topic; firewalls/proxies imposing shorter client timeouts that abort the poll; function logic dropping the message (exception swallowed).

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/51181f9ff6aca783. Report an issue: GitHub.