SSE tokens arrive all at once behind NGINX: Check response buffering
If requests stream directly from the application but tokens arrive together through NGINX, first test whether the proxy is buffering the response. Compare the same harmless request on both paths before changing configuration, since the application, another intermediary, or the viewer can produce a similar symptom.
1. Record the first and second event, not just the status
Use a staging route or an authorized diagnostic endpoint that emits three complete SSE events with known gaps. SSE frames end with a blank line. Compare the event timestamps at the upstream and public-facing paths using the same request and client. In curl, -N disables the client's output buffering. A status of 200 and the right content type show that the request was accepted, but they do not tell you when complete events became visible.
curl -N -sS http://127.0.0.1:8080/test/events
curl -N -sS https://staging.example.test/test/eventsThe hostnames and ports are examples. Run the direct request only through an authorized local path. Keep production tokens and real prompts out of the diagnostic stream.
2. Change the smallest applicable NGINX route
NGINX can buffer the response it receives from an upstream server. If your route is dedicated to SSE and buffers today, try the proxy_buffering off; directive in that route's existing location configuration. An upstream that deliberately controls its own behavior can instead send X-Accel-Buffering: no if the proxy is configured to honor it. Choose one mechanism so you can attribute the result. The setting addresses response buffering. proxy_request_buffering concerns what NGINX receives from the client and will not resolve the response-side symptom.
Validate and roll out the configuration using your environment's normal review, nginx -t check, and reload procedure. Keep buffering for unaffected routes. Streaming connections may stay open longer and consume resources differently, so evaluate the selected route under its expected concurrency before a wider rollout.
3. Prove the endpoint improved on the real path
Hypothetical example: the upstream emits complete events at seconds 0, 2, and 4. Before the change the proxy delivers all three at second 4. After the change the same client receives events near seconds 0, 2, and 4. Those observations support the buffering diagnosis. The times illustrate the comparison, not a measurement from a deployed service.
If both direct and proxied requests still arrive in a burst, inspect whether the application flushes each complete event. If NGINX passes the test on staging but the browser still batches events in production, compare a path that includes the load balancer or CDN. Then check the browser’s event handler rather than assuming the streaming transport failed. Treat front-end rendering time and network arrival time as separate observations.
댓글
댓글 쓰기
안녕하세요 :)