Skip to content

Close HttpServer client connections when draining#4878

Open
mfazalul wants to merge 1 commit intolivekit:mainfrom
mfazalul:mfazalul/close-http-client-connections
Open

Close HttpServer client connections when draining#4878
mfazalul wants to merge 1 commit intolivekit:mainfrom
mfazalul:mfazalul/close-http-client-connections

Conversation

@mfazalul
Copy link

Summary

When the agent server is deployed with Telegraf scraping the /metrics endpoint with default configs, there is a persistent connection kept alive indefinitely. When a SIGTERM command is sent, it is unable to shut down the agent server gracefully and it gets stuck in the "process exiting" stage. This PR fixes the issue by calling close_client.

Unfortunately, close_clients is only available with Python versions >= 3.13. I haven't been able to identify a similar fix for versions 3.10 to 3.12 which LiveKit supports.

An alternative fix is to set Telegraf configs to close and start new connections with each scrape:

  [inputs.prometheus.http_headers]
    Connection = "close"

Tested via:

  1. Run the agent server locally and expose a Prometheus port.
  2. Run Telegraf locally with the /metrics endpoint as input.
  3. Send a SIGTERM command to the agent server process. This would not stop the agent.
  4. Stop the Telegraf service. This would stop the agent server as well.
  5. With this fix, the Telegraf service does not need to be stopped for the agent to exit. It does not affect the graceful shutdowns when there are active agent sessions

@CLAassistant
Copy link

CLAassistant commented Feb 17, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments