Cursor realtime

Server-Sent Events Disconnecting in Cursor Application

Your Cursor-generated application uses Server-Sent Events (SSE) for real-time updates (live notifications, streaming responses, dashboards), but the SSE connection drops after a few seconds or minutes. Users see the real-time feed freeze, and the browser's EventSource silently reconnects only to disconnect again in a loop.

SSE connections are long-lived HTTP connections that must stay open indefinitely. This conflicts with many infrastructure components that expect short request-response cycles. Reverse proxies, load balancers, serverless platforms, and CDNs all have default timeouts that terminate SSE connections prematurely.

The issue is often intermittent — it works fine during development where there's no proxy layer, but fails in production where Nginx, Cloudflare, or a serverless platform sits between the client and server.

Error Messages You Might See

EventSource failed: net::ERR_INCOMPLETE_CHUNKED_ENCODING EventSource connection lost, reconnecting... 504 Gateway Timeout Error: stream timeout after 60000ms ReadableStream has been disturbed or locked
EventSource failed: net::ERR_INCOMPLETE_CHUNKED_ENCODINGEventSource connection lost, reconnecting...504 Gateway TimeoutError: stream timeout after 60000msReadableStream has been disturbed or locked

Common Causes

  • Reverse proxy timeout — Nginx, Apache, or Cloudflare terminates idle connections after 60-120 seconds by default
  • Serverless function timeout — Vercel (30s), Netlify (26s), and Lambda (15min max) kill long-running functions, terminating the SSE stream
  • No keep-alive heartbeat — Without periodic data sent on the connection, intermediaries assume it's dead and close it
  • Missing SSE headers — The response lacks required headers like Content-Type: text/event-stream, Cache-Control: no-cache, or Connection: keep-alive
  • Response buffering enabled — Nginx or Node.js response compression buffers SSE data instead of streaming it, causing events to arrive in batches or not at all

How to Fix It

  1. Send heartbeat comments every 15-30 seconds — Send SSE comment lines (: heartbeat\n\n) at regular intervals to keep the connection alive through proxies and load balancers
  2. Configure proxy timeouts — For Nginx: set proxy_read_timeout 86400s; and proxy_buffering off;. For Cloudflare: enable WebSockets/SSE in the dashboard or use Cloudflare Tunnel
  3. Disable response buffering — Add X-Accel-Buffering: no header for Nginx, and disable compression on SSE endpoints
  4. Implement robust client reconnection — Use EventSource's built-in reconnection with a custom retry: field, and include Last-Event-ID handling to resume from where the client left off
  5. Avoid serverless for SSE — If your SSE needs long-lived connections, deploy on a traditional server (VPS, container) rather than serverless functions. Alternatively, use a managed service like Ably or Pusher
  6. Set correct response headers — Ensure every SSE endpoint sends: Content-Type: text/event-stream, Cache-Control: no-cache, Connection: keep-alive

Real developers can help you.

Victor Denisov Victor Denisov Developer Simon A. Simon A. I'm a backend developer building APIs, emulators, and interactive game systems. Professionally, I've developed Java/Spring reporting solutions, managed relational and NoSQL databases, and implemented CI/CD workflows. David Olverson David Olverson Solo dev shipping production apps with AI-assisted development. I specialize in rescuing broken Lovable/Bolt/Cursor builds and taking them to production. 10+ apps shipped including SaaS CRMs, gaming platforms, real estate tools, and Discord bots. Stack: Next.js 16, TypeScript, Tailwind CSS, FastAPI, PostgreSQL, Prisma. I use Claude Code with 50+ custom skills for rapid delivery. Average turnaround: 2-4 weeks from broken prototype to production. Richard McSorley Richard McSorley Full-Stack Software Engineer with 8+ years building high-performance applications for enterprise clients. Shipped production systems at Walmart (4,000+ stores), Cigna (20M+ users), and Arkansas Blue Cross. 5 patents in retail/supply chain tech. Currently focused on AI integrations, automation tools, and TypeScript-first architectures. hanson1014 hanson1014 Full-stack developer experienced in fixing and deploying AI-generated apps from Lovable, Bolt.new, Cursor, and Replit. I specialize in debugging Supabase integration issues (auth flows, RLS policies, database connections), fixing broken deployments, resolving routing/blank screen problems, and cleaning up messy React/Vite codebases. I also build production apps with the Claude API and have shipped a Mac desktop dev tool (Nexterm from scratch. Based in Hong Kong, fast turnaround. Dor Yaloz Dor Yaloz SW engineer with 6+ years of experience, I worked with React/Node/Python did projects with React+Capacitor.js for ios Supabase expert Taufan Taufan I’m a product-focused engineer and tech leader who builds scalable systems and turns ideas into production-ready platforms. Over the past years, I’ve worked across startups and fast-moving teams, leading backend architecture, improving system reliability, and shipping products used by thousands of users. My strength is not just writing code — but connecting product vision, technical execution, and business impact. Jared Hasson Jared Hasson Full time lead founding dev at a cyber security saas startup, with 10 yoe and a bachelor's in CS. Building & debugging software products is what I've spent my time on for forever Vlad Temian Vlad Temian 15+ years shipping production infrastructure for startups. Former CTO at qed.builders (acquired by The Sandbox). Cursor ambassador and agentic tooling builder. I've scaled systems, automated deployments, and built observability tools for AI coding workflows. I specialize in taking vibe-coded apps from broken prototype to production-ready: fixing Supabase auth/RLS, Stripe integrations, deployment pipelines, and cleaning up AI-generated spaghetti. I build tools in this space (agentprobe, claudebin, micode) and understand both sides: how AI generates code and why it breaks. https://blog.vtemian.com/ Jen Jacobsen Jen Jacobsen I’m a Full-Stack Developer with over 10 years of experience building modern web and mobile applications. I enjoy working across the full product lifecycle — turning ideas into real, well-built products that are intuitive for users and scalable for businesses. I particularly enjoy building mobile apps, modern web platforms, and solving complex technical problems in a way that keeps systems clean, reliable, and easy to maintain.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

Can I use SSE with serverless platforms like Vercel?

Standard SSE with long-lived connections doesn't work well with serverless platforms due to function execution time limits. Vercel supports streaming responses for up to 30 seconds. For longer connections, use a dedicated WebSocket service (Ably, Pusher, Supabase Realtime) or deploy the SSE endpoint on a traditional server.

How is SSE different from WebSockets?

SSE is unidirectional (server to client only), uses standard HTTP, and has built-in reconnection. WebSockets are bidirectional, use a separate protocol (ws://), and require manual reconnection logic. Use SSE when you only need server-to-client updates; use WebSockets when you need two-way communication.

Related Cursor Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help