Server-Sent Events Errors — SSE Connection and Streaming Failures
About Server-Sent Events Errors
Troubleshoot Server-Sent Events (SSE) connection drops, CORS issues, and buffering problems for reliable real-time HTTP streaming. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: Server-Sent Events (SSE) provide one-way real-time data streaming from server to client over HTTP. SSE connections use the text/event-stream content type and keep-alive HTTP connections. Proxy servers and load balancers may buffer SSE responses, causing delayed or batched delivery. Browser EventSource API automatically reconnects on connection drops with Last-Event-ID header. Maximum concurrent SSE connections per domain is limited (6 in HTTP/1.1, higher in HTTP/2). Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: Reverse proxy (Nginx/Apache) buffering the event stream instead of passing through immediately. Load balancer idle timeout closing long-lived SSE connections after inactivity. CORS headers missing on the SSE endpoint preventing cross-origin connections. HTTP/1.1 connection limit (6 per domain) exhausted by multiple SSE connections. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Disable proxy buffering in Nginx: add 'proxy_buffering off;' and 'X-Accel-Buffering: no' header. Set appropriate Cache-Control headers: 'no-cache, no-transform' to prevent intermediate caching. Add CORS headers: Access-Control-Allow-Origin and Access-Control-Allow-Credentials for cross-origin SSE. Implement heartbeat messages (empty comments) every 15-30 seconds to prevent idle timeout disconnections. Use HTTP/2 to avoid the 6-connection-per-domain limit of HTTP/1.1. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our HTTP Status Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
What is the difference between SSE and WebSocket?
SSE is one-way (server to client) over standard HTTP, with automatic reconnection. WebSocket is bidirectional over a separate protocol. SSE is simpler for scenarios where only the server pushes data.
Overview
Troubleshoot Server-Sent Events (SSE) connection drops, CORS issues, and buffering problems for reliable real-time HTTP streaming.
Key Details
- Server-Sent Events (SSE) provide one-way real-time data streaming from server to client over HTTP
- SSE connections use the text/event-stream content type and keep-alive HTTP connections
- Proxy servers and load balancers may buffer SSE responses, causing delayed or batched delivery
- Browser EventSource API automatically reconnects on connection drops with Last-Event-ID header
- Maximum concurrent SSE connections per domain is limited (6 in HTTP/1.1, higher in HTTP/2)
Common Causes
- Reverse proxy (Nginx/Apache) buffering the event stream instead of passing through immediately
- Load balancer idle timeout closing long-lived SSE connections after inactivity
- CORS headers missing on the SSE endpoint preventing cross-origin connections
- HTTP/1.1 connection limit (6 per domain) exhausted by multiple SSE connections
Steps
- 1Disable proxy buffering in Nginx: add 'proxy_buffering off;' and 'X-Accel-Buffering: no' header
- 2Set appropriate Cache-Control headers: 'no-cache, no-transform' to prevent intermediate caching
- 3Add CORS headers: Access-Control-Allow-Origin and Access-Control-Allow-Credentials for cross-origin SSE
- 4Implement heartbeat messages (empty comments) every 15-30 seconds to prevent idle timeout disconnections
- 5Use HTTP/2 to avoid the 6-connection-per-domain limit of HTTP/1.1