Why self-hosted Langfuse returns intermittent 502 and 504 errors
Intermittent 502 and 504 errors on a self-hosted Langfuse usually mean the load balancer in front of Langfuse Web gave up on a connection that the application still considered valid, or that the application took longer to answer than the proxy allowed. The UI loads most of the time, SDKs retry sometimes succeed, and the failures look random. This page explains how to find the mismatch that causes them and how to fix it, including the separate case where blob storage writes run out of socket capacity. It assumes you already run Langfuse following the Langfuse self-hosting docs and the Langfuse scaling guide, which remain the baseline for sizing.
The request path is short but has several hops. A browser or SDK calls your load balancer or ingress, which forwards to Langfuse Web, the container that serves both the UI and the APIs. Langfuse Web reads and writes PostgreSQL for application state, queries ClickHouse for analytical views, and uses S3-compatible blob storage for event payloads. In plain terms, a 502 means the proxy received a bad or closed response from the upstream, often because the upstream closed an idle keep-alive connection just as the proxy reused it. A 504 means the proxy waited for the upstream and the wait exceeded its timeout. The two errors point to different fixes, so the first task is to read which one your proxy logs and which hop logged the failure.
Teams need this work when the errors are sporadic enough to hide in normal traffic but frequent enough to break trace ingestion, prompt pulls or evaluation runs. Confirm the exact load balancer type, its idle and keep-alive settings, the Langfuse Web keep-alive configuration in your release, and whether blob storage sits on a shared endpoint with connection limits. Record these values before changing anything, because a single timeout raised in isolation often moves the failure to another hop rather than removing it.
Where the gateway errors originate in the request path
The request starts at the SDK or client, passes through the load balancer or ingress, and reaches Langfuse Web, which writes raw event payloads to S3-compatible blob storage and hands work to Langfuse Worker through Redis or Valkey. The worker then writes to ClickHouse. A 502 or 504 is returned by the gateway, not by Langfuse, so the first check is which hop closed the connection: the idle timeout on the load balancer and the keep-alive timeout on Langfuse Web must be set so the gateway always closes idle connections last. Blob storage socket limits surface on the Web-to-storage write path, so check those connections as well.
Request path from SDK to storage, with the gateway timeout zone marked.
How to tell a 502 from a 504 before changing anything
A 502 and a 504 point to different failures, and both can look identical to users. Collect the load balancer, Langfuse Web and blob storage signals for the same time window before you change any timeout, so the fix targets the component that actually failed.
Load balancer status codes and access logs
Start with the load balancer access log. Note which status code each failed request returned, the upstream address it selected, and the request duration. A 502 usually means the gateway received an invalid or closed response from Langfuse Web, while a 504 means the gateway gave up waiting. Compare the duration on each failed line with the configured idle timeout to see which limit was hit.
Langfuse Web container logs at failure time
Pull the Langfuse Web container logs for the same minutes as the failed requests. Look for connection resets, closed sockets, unhandled errors or long-running requests logged just before the failure. Silence in the web logs while the gateway reports 504s suggests requests were stuck before the application logged anything, which points toward the network path or the upstream connection handling.
Ingestion calls versus UI calls
Split the failed requests by path. Ingestion traffic from SDKs and the OpenTelemetry endpoint tends to arrive in bursts with many short requests and possibly large payloads, while UI and API reads have their own latency profile. If failures concentrate on one group, the cause is more likely request size, batching or the capacity of that path. If they spread across both, look at shared resources such as the connection pool or the gateway itself.
Blob storage write activity
Check whether failures line up with bursts of writes to the S3-compatible blob store. Langfuse stores event payloads in blob storage during ingestion, so a surge of uploads can exhaust outbound sockets or slow responses on the web path. Ask your storage team for connection and error metrics from the same window. A correlation supports a socket capacity investigation, while no correlation points elsewhere.
Deployments and traffic spikes
Compare the failure timestamps with rollout history, configuration changes to the load balancer, and known peaks in SDK traffic. Failures that begin right after a deployment often trace to new pods receiving traffic before they are ready, or to changed timeout settings. Failures that track daily traffic peaks point toward capacity and concurrency. Record the answer before editing any setting so the change can be verified later.
Timeout and capacity settings and when each fits
This table compares the five levers that usually sit behind intermittent 502 and 504 responses from self-hosted Langfuse: load balancer idle timeout, keep-alive timeouts, SDK retries, web replicas or a split ingestion deployment, and blob storage socket limits. Read each row as a question to answer in your environment before changing anything. The main takeaway is that the timeout values must be ordered correctly across every hop, and that capacity changes only help when the bottleneck is actually capacity.
| Lever | What it controls and when to change it | Trade-off |
|---|---|---|
| Load balancer idle timeout | Sets how long the load balancer keeps an idle client or upstream connection open. Review it when 504s cluster on slow ingestion or export requests, and confirm the maximum value your load balancer accepts. | A longer timeout holds more connections open and can hide slow backends; a shorter one drops legitimate slow requests. |
| Keep-alive timeout on Langfuse web | Controls how long the Node.js web container keeps idle upstream connections open. Review it when 502s appear after quiet periods, and confirm the default for your Langfuse version in its self-hosting documentation. | Raising it reduces new connection setup but can leave stale sockets the proxy tries to reuse, which produces 502s. |
| Keep-alive timeout on proxies in front | Controls idle connection reuse at any ingress controller, reverse proxy or CDN between the load balancer and Langfuse web. Review it whenever a proxy sits in the path, and confirm its documented setting. | Every hop must keep connections open at least as long as the hop before it; a mismatch in either direction causes intermittent resets. |
| Client SDK retry behavior | Determines whether a failed or timed-out ingestion request is resent. Review it when 502 or 504 responses coincide with duplicate or missing events, and confirm retry settings in your SDK version. | Retries recover transient gateway errors but add load during an outage, so they should back off rather than repeat instantly. |
| Number of web replicas | Sets how many web containers share requests. Add replicas when CPU or memory pressure on web coincides with gateway errors, and confirm resource limits in the scaling guide. | More replicas raise database and ClickHouse connection use and cost more compute; they do not fix a single slow dependency. |
| Split ingestion and UI deployments | Separates high-volume ingestion traffic from interactive UI and API traffic. Consider it when heavy trace ingestion makes the UI time out, following the Langfuse scaling guidance. | Adds a second deployment, routing rules and tuning to maintain, and needs care that both paths reach the same services. |
| Blob storage connection or socket limits | Caps how many concurrent connections the web or worker containers open to S3-compatible storage. Review it when 502 or 504 errors occur during bursts of event writes and storage logs show connection exhaustion, and confirm limits with your storage vendor. | Higher limits allow more parallel writes but can overload the storage endpoint or exhaust file descriptors on the host. |
Fix the timeout chain in the right order
This sequence isolates which hop in the path closes idle connections first, then aligns each timeout from the inside out so that gateway errors stop appearing under normal and peak load. Each step ends with a check that proves the change worked before the next one starts.
Capture a baseline of 502 and 504 errors
Before changing anything, the operator pulls the load balancer access logs and the Langfuse web container logs for a window where errors occur, then counts 502 and 504 responses by endpoint, by hour and by target instance. Note whether errors cluster on ingestion API calls, UI requests or both, and whether they follow traffic peaks. Record the load balancer's idle timeout and any error fields it logs, such as a target reset or a target timeout. The step is complete when the team has a dated baseline count that can be compared after each change.
Confirm the Langfuse version and topology
Confirm the running Langfuse version from the deployed image tags, not from memory, and record whether the deployment is a single VM, a Kubernetes install or a split web deployment for ingestion and UI. List every hop between the client and the web container, including any CDN, ingress controller, reverse proxy and the load balancer, and note each hop's idle timeout and keep-alive setting. Check whether the blob storage client shares a network path with the web container. The step is complete when a written diagram lists each hop with its timeout values and the Langfuse version, so later changes target the correct component.
Align keep-alive timeouts on each upstream
Make the keep-alive timeout on each upstream server, reverse proxy or ingress longer than the idle timeout used by the hop in front of it, so the proxy never reuses a connection the backend has already closed. The operator changes these values in the reverse proxy or ingress configuration and restarts or reloads only that component, then confirms the setting with the component's configuration check command. Confirm the exact keep-alive key for the Node.js-based web container and the proxy in use against their current documentation, since the settings differ by runtime. The step is complete when the configuration validates and a sample of connections shows reuse without resets in the logs.
Set load balancer idle timeout to the longest request
Measure the longest expected request for ingestion, trace listing and export endpoints from the baseline logs, then set the load balancer idle timeout above that value, so slow but valid responses are not cut off with a 504. Keep the value below the upstream keep-alive timeout set in the previous step so the load balancer closes idle connections before the backend does. The change belongs to the team that owns the load balancer, and it should be reviewed alongside any ingress timeout. The step is complete when the load balancer setting is recorded in change management and a sample of long requests returns 200 instead of 504.
Check blob storage socket and connection limits
Under heavy ingestion, the web and worker containers write events to S3-compatible blob storage, and exhausted sockets or a low connection pool there can stall requests until the gateway times out. Ask the storage team for the connection limit, per-client concurrency and any request timeout on the object store, and confirm the S3 client settings Langfuse uses in your version. Check the path between the containers and the storage endpoint for NAT, firewall or proxy idle timeouts that differ from the gateway. Look for socket exhaustion or connection errors in container logs during peaks. The step is complete when the storage limits are documented and the logs show no connection errors during a peak window.
Retest under load and compare error counts
Repeat the baseline query over a window with similar traffic and run a controlled load test against ingestion and UI endpoints that reproduces the earlier peak. Compare 502 and 504 counts per endpoint and per target instance with the baseline, and confirm that connection reset entries in the load balancer logs have stopped. Keep the previous configuration available so the change can be reverted if errors return. The step is complete when status codes for the test window show a sustained drop in 502 and 504 responses and the results are signed off by the operator who owns the platform.
When blob storage socket limits cause gateway timeouts
Blob storage socket exhaustion is the less obvious cause of gateway errors in self-hosted Langfuse. When the ingestion path writes many small event objects to S3-compatible storage in a short burst, the web or worker host can open a large number of outbound connections. Once the host runs out of usable sockets or the connection pool saturates, requests queue inside the container, responses slow down, and the load balancer gives up and returns a 502 or 504 even though the application itself has not crashed. The symptom usually appears during batch uploads, SDK retry storms or backfills, not at steady traffic levels.
To confirm this pattern, line up gateway error timestamps with write activity. Check whether the 502 and 504 spikes coincide with bursts of ingestion, and whether they also appear in worker logs as slow or failed storage calls. On the affected hosts, compare the count of open TCP sockets in the established and time-wait states during a spike against a quiet period, and check whether the count climbs toward a ceiling set by the operating system or the container runtime. Measure request latency to the storage endpoint from the same host, separately from the latency the gateway reports. A storage round trip that grows from milliseconds into seconds during the burst points to the storage path rather than the web tier.
Before changing settings, confirm the limits with your storage provider or platform team. Ask what concurrent connection limits, request rate limits and throttling responses apply to your bucket or endpoint, and whether a proxy or gateway in front of the storage adds its own connection ceiling. Confirm the file descriptor and socket limits on the host and in the container, and whether the storage endpoint is reached over a shared network path that other services also load. The fix is usually a combination of reducing burst concurrency at the ingestion layer, reusing connections, and raising limits only after the provider confirms the ceiling. Keep the blob storage findings separate from the keep-alive settings in the load balancer, because fixing one does not remove the other.
Security and operational considerations while tuning gateways
Timeout changes look small in a load balancer console, but they touch request security, capacity and incident response at once. The cards below cover the guardrails that keep a fix for intermittent 502 and 504 errors from creating a new exposure.
Keep TLS and header settings intact
When you edit idle timeouts or keep-alive values, leave the listener's TLS policy, certificate chain and forwarded headers untouched. Changing a timeout on a listener often means recreating or re-editing it, and a careless save can drop a cipher restriction or the X-Forwarded-Proto and X-Forwarded-For headers that Langfuse uses to build URLs and log client addresses. Before and after the change, confirm the negotiated protocol and check that sign-in redirects still land on the HTTPS hostname.
Avoid unbounded timeout widening
Raising timeouts until 502 and 504 errors disappear hides the problem and gives slow or hostile clients longer to hold connections open. Each open connection consumes a socket and a worker slot on the gateway and on langfuse-web, so a flood of slow requests can exhaust capacity for trace ingestion and the UI at the same time. Set the smallest value that clears measured response times, and check connection counts under a load test before you accept the new value.
Log and monitor gateway errors separately
Application logs from Langfuse Web do not record requests that the load balancer abandoned, so a 504 can be invisible to the application team. Keep gateway access logs and error counts as their own stream, with status code, upstream response time and target address, and alert on the 502 and 504 rate by route. Separating these streams lets you tell a gateway timeout from an application error when the next incident starts.
Restrict who can change gateway config
Timeouts, health check paths and target groups are security-relevant settings, and a change to a health check path can route traffic to the wrong backend or mark healthy instances as failed. Limit write access to the load balancer to a named group, require review for changes to listeners and target groups, and keep break-glass access documented. Confirm that the team changing gateway settings is not the only team able to see gateway logs.
Record each change for audit
Keep a change record for every timeout, keep-alive or limit change, with the old value, the new value, the reason, the person who approved it and the load test that supported it. When a later incident traces back to a gateway setting, this record shows whether the change caused it or whether the error was already present. Store the record with the infrastructure code or the change ticket, and review it when you upgrade Langfuse or the gateway itself.
Questions teams ask about fixing gateway errors in self-hosted Langfuse
How long does it take to fix intermittent 502 and 504 errors in self-hosted Langfuse?
The duration depends mostly on how many layers sit between the client and Langfuse Web, and on whether the team can reproduce the errors on demand. A single load balancer in front of one web container, with logs that show which component returned the error, is usually quicker to diagnose than a chain of proxies, ingress controllers and object storage endpoints. Duration also depends on change control: timeout and keep-alive changes often need a maintenance window and a staged rollout across environments. No duration is set here. Ask a partner for a timeline based on your topology, your log access and your approval process, and confirm how many environments the fix must pass through before production.
What effort does the operator's team need to put into this work?
Most of the effort goes to collecting evidence and making controlled configuration changes, not to writing new code. Your team needs access to load balancer and ingress settings, Langfuse Web and Worker logs, and the configuration of the blob storage endpoint. Someone who owns the network path must confirm which component closes idle connections first. Expect the work to include reproducing the errors under load, comparing timeout values across each hop, and retesting after each change. Confirm who can approve edits to the load balancer, because those settings are often owned by a different team from the one running Langfuse.
Can our own team fix these gateway errors without a partner?
Yes, if your team already runs the load balancer and the Langfuse deployment and can read their logs. The core task is aligning idle timeouts and keep-alive settings so that the proxy never closes a connection that Langfuse Web is still using, and so that long-running requests have enough time to finish. Teams that lack experience with proxy timeout semantics, or that run several gateways in series, often find the cause faster with an outside review. A practical split is to have your team collect logs and timing data while a partner or internal specialist reviews the timeout chain. Confirm your own capacity before deciding.
What does a fixed-scope engagement for this problem cover?
A fixed-scope engagement sets out the scope, deliverables and timeline in writing before work starts. For gateway errors, a typical scope covers reviewing the request path from client to load balancer, ingress, Langfuse Web and blob storage; identifying the idle timeout and keep-alive values on each hop; recommending and applying agreed changes in your environment; and checking the result with repeat tests. Confirm whether the scope includes capacity tests for blob storage writes, changes to Langfuse Worker settings, and the handover documentation your operations team will need. Anything outside the written scope is quoted separately.
Is changing load balancer or proxy timeouts risky?
Changing timeouts carries moderate risk when it is done without a baseline, and low risk when it is staged and measured. Raising idle timeouts can keep dead connections open longer and tie up sockets, while lowering them can cut off valid long requests. The safe pattern is to record current values, change one hop at a time in a non-production environment, run representative traffic, and roll back if error rates rise. Keep the keep-alive timeout on the upstream side longer than the idle timeout on the proxy side, so the proxy, not Langfuse, closes connections. Confirm the exact setting names with your load balancer vendor, since they differ between products.
Do SDK retries hide the 502 and 504 errors?
Often they do, at least partly. Langfuse SDKs can retry failed sends, so a gateway error may be retried and succeed without anyone noticing in the application. That hides the symptom from application owners but not from the platform. Gateway logs, load balancer metrics and Langfuse Web logs still show the failed attempts, and repeated retries add load and delay. Retries also do not help if the same error repeats on every attempt. Check your SDK configuration and the retry behavior of your ingestion path, and treat rising retry volume as a signal that the gateway needs attention.
What should we send a partner to start the work?
Send enough evidence for the partner to see where errors occur and which hop produced them. Useful inputs include the architecture diagram from client to storage, the load balancer and ingress configuration with timeout and keep-alive values, the Langfuse Helm values or Compose file, the version of Langfuse you run, and the timestamps and status codes of recent 502 and 504 errors. Add blob storage endpoint details and any socket or connection limits you know about. Also state your change-approval process and the environments available for testing. Those inputs let a partner write a fixed-scope proposal from the written scope rather than guessing.
How the investigation and fix are scoped with a partner
A written scope should come before anyone changes a load balancer, ingress or container setting. DeployOpen plans and implements self-hosted Langfuse inside your own infrastructure, so the 502 and 504 work is agreed as a fixed scope with named access, deliverables and a retest before it starts. Ask for the scope to name each system the work touches: the load balancer or ingress that fronts Langfuse Web, the Langfuse Web containers, the blob storage endpoint used for event writes, and the Langfuse Worker, because timeouts on any of these can surface as a gateway error at the edge.
The access list is the part most often left vague. Confirm in writing which configuration you will provide: read access to the load balancer listener and backend settings, including keep-alive and idle timeout values, the Langfuse Web deployment manifest or Compose file, and the environment variables that control the server and storage client. Confirm also how log review is handled, including which access logs, gateway logs and container logs are exported, over what period, and whether they can be shared with the partner or must be reviewed on your side. Redact credentials and personal data in any extract before it leaves your environment.
The change plan and retest should be written as deliverables, not as an open-ended effort. Ask for a plan that lists each proposed timeout or capacity change, the order in which the load balancer and Langfuse settings are altered, the rollback step for each one, and the test that proves the error rate has dropped under representative traffic. Confirm with your team which maintenance window and change approval process applies, and ask the partner to state what is one-time (the investigation and fix) and what recurs (monitoring and any later upgrade retest). Avoid committing to response times in the scope unless they appear in a signed agreement.
How DeployOpen works on this
DeployOpen approaches fixing intermittent 502 and 504 errors in self-hosted Langfuse as a bounded piece of work inside your own infrastructure. We start from the gateway logs and timeout settings you already run, change them in a controlled order, and prove the fix under real ingestion before closing the engagement.
How we scope
- We inventory the load balancer, ingress and Langfuse web timeout and keep-alive settings in your environment.
- The written scope names the gateway, the blob storage endpoint and the change window for each configuration edit.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before any change starts.
- Ask the quote to separate the gateway review from any blob storage socket work, since each depends on different access.
How we build
- We align load balancer idle timeouts with the keep-alive behavior of Langfuse web, one change at a time.
- We test blob storage write behavior under concurrent ingestion to confirm whether socket limits cause the errors.
- Each change is recorded with a before and after reading from access logs and error rates.
- Changes are applied to a staging copy of your deployment first where your environment allows it.
How we hand over
- You receive the final timeout values, the reasoning for each, and the rollback steps in a written runbook.
- The runbook lists which gateway and storage metrics to watch and the thresholds that should prompt a review.
- We walk your platform and operations team through the configuration so they can reproduce the fix.
- Retesting results are included so you can show the fix was verified before handover.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after the initial fix.
- A retainer can cover re-checking gateway timeouts after Langfuse upgrades or load balancer changes.
- Ask what response and availability terms apply before signing, since these are set in the written agreement.
- Support covers your self-hosted instance only, running in your cloud account, data center or air-gapped network.

