{"record":{"id":"51181f9ff6aca783","repo":"apache/pulsar","slug":"request-timed-out","errorCode":null,"errorMessage":"Request Timed Out","messagePattern":"Request Timed Out","errorType":"http","errorClass":"RestException","httpStatus":408,"severity":"error","filePath":"pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java","lineNumber":1218,"sourceCode":"            while (curTime < maxTime) {\n                Message<?> msg = reader.readNext(10000, TimeUnit.MILLISECONDS);\n                if (msg == null) {\n                    break;\n                }\n                if (msg.getProperties().containsKey(\"__pfn_input_msg_id__\")\n                        && msg.getProperties().containsKey(\"__pfn_input_topic__\")) {\n                    MessageId newMsgId = MessageId.fromByteArray(\n                            Base64.getDecoder().decode((String) msg.getProperties().get(\"__pfn_input_msg_id__\")));\n\n                    if (msgId.equals(newMsgId)\n                            && msg.getProperties().get(\"__pfn_input_topic__\")\n                            .equals(TopicName.get(inputTopicToWrite).toString())) {\n                        return new String(msg.getData());\n                    }\n                }\n                curTime = System.currentTimeMillis();\n            }\n            throw new RestException(Status.REQUEST_TIMEOUT, \"Request Timed Out\");\n        } catch (SchemaSerializationException e) {\n            throw new RestException(Status.BAD_REQUEST, String.format(\n                    \"Failed to serialize input with error: %s. Please check\"\n                            + \"if input data conforms with the schema of the input topic.\",\n                    e.getMessage()));\n        } catch (IOException e) {\n            throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());\n        } finally {\n            if (reader != null) {\n                reader.closeAsync();\n            }\n            if (producer != null) {\n                producer.closeAsync();\n            }\n        }\n    }\n\n    @Override","sourceCodeStart":1200,"sourceCodeEnd":1236,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java#L1200-L1236","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Retry the trigger — first-invocation warm-up often makes the second attempt succeed.","Increase the client/HTTP read timeout for the trigger request so the worker's polling window isn't cut short.","Inspect function logs and the output topic with a consumer to confirm whether output was actually produced.","Reduce function startup cost or input backlog so processing fits the timeout window."],"exampleFix":"// before: default curl timeout too short\ncurl -X POST --data-binary 'x' .../functions/.../f?topic=src\n// after\ncurl -m 120 -X POST --data-binary 'x' .../functions/.../f?topic=src","handlingStrategy":"retry","validationCode":"// Choose a client read timeout comfortably above expected processing time\nint readTimeoutMs = Math.max(functionMaxProcessingMs * 2, 120_000);","typeGuard":null,"tryCatchPattern":"for (int i = 0; i < 3; i++) {\n  try { return triggerWithTimeout(...); }\n  catch (PulsarAdminException e) {\n    if (e.getResponseStatus() == 408) { backoff(i); continue; }\n    throw e;\n  }\n}\nthrow new TimeoutException(\"trigger did not return within retries\");","preventionTips":["Warm up the function with a dummy invocation before latency-sensitive triggers","Keep output-topic backlog low; monitor consumer lag","Verify the function actually publishes to the expected output topic before relying on trigger round-trips","Configure generous HTTP read timeouts on trigger clients"],"tags":["timeout","pulsar-functions","rest-api"],"backgroundTag":"request-timeout","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}