Content Deep Dive
How to keep an HTTP connection alive for 9 hours
Blog post from Snyk
Post Details
Company
Date Published
Author
Micah Silverman
Word Count
2,391
Language
English
Hacker News Points
3
Summary
The HTTP connection was kept alive for almost 9 hours by using Server Sent Events (SSE) to send periodic updates on the status of a long-running process. The process itself was kicked off in an asynchronous manner, with a backoff/retry mechanism to handle API rate limits and other potential errors. To mitigate issues with Heroku's aggressive closure of idle connections, another asynchronous method was added to drop "heartbeat" SSE messages at regular intervals. This approach allowed the long-running process to run in the background without presenting as idle, ensuring its completion without interruption. The use of SSE also provided a way for clients to receive updates on the process's progress in real-time.