fix: close writer and notify relay on target EOF in edge agent#77
Merged
fix: close writer and notify relay on target EOF in edge agent#77
Conversation
read_from_tcp_and_send() broke on empty read (remote EOF) without
closing the asyncio StreamWriter or removing the entry from
active_connections. Each SSH/VNC session that ends naturally leaked one
file descriptor. On a default systemd soft limit of 1024 fds the process
eventually exhausts its budget; asyncio.open_connection() then fails
with [Errno 16] Device or resource busy (Python 3.13 happy-eyeballs
translates EMFILE as EBUSY).
Fix: wrap the read loop in try/finally that
- calls writer.close() to release the fd
- pops from active_connections so stale entries don't accumulate
- sends EtRConnectionResetMessage to notify the relay the target
closed its side (guarded against a closed websocket)
elikoga
added a commit
to Thymis-io/thymis
that referenced
this pull request
Mar 27, 2026
Pins to Thymis-io/http-network-relay#77 which fixes the fd leak in edge_agent read_from_tcp_and_send(). Revert the pin to main once that PR is merged.
Member
Author
|
Can't hurt, right? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
read_from_tcp_and_send()exited on empty read (remote EOF) without closing theasyncio.StreamWriteror removing the entry fromactive_connections. Every SSH/VNC session that ends naturally leaked one file descriptor.On the default systemd soft limit of 1024 fds the agent exhausts its budget;
asyncio.open_connection()then fails with[Errno 16] Device or resource busy(Python 3.13 happy-eyeballs translatesEMFILEasEBUSY). The agent stops proxying all connections until restarted.Observed in production on a HomePi4 running thymis-agent continuously — terminal/SSH relay broke after accumulated sessions hit the fd ceiling.
Fix
Wrap the read loop in
try/finallythat:writer.close()to release the fdactive_connectionsso stale entries don't accumulateEtRConnectionResetMessageto notify the relay the target closed its side (guarded against a closed websocket)