Fix file descriptor leaks causing server instability#7
Open
amalg wants to merge 1 commit intoohAnd:mainfrom
Open
Fix file descriptor leaks causing server instability#7amalg wants to merge 1 commit intoohAnd:mainfrom
amalg wants to merge 1 commit intoohAnd:mainfrom
Conversation
This commit addresses file descriptor exhaustion (OSError errno 24) that
causes the TRMNL server to become unresponsive after extended operation.
Changes:
- Add requests.Session for HTTP connection pooling instead of creating
new connections for each request
- Fix add_footer_to_image() to explicitly close PIL Image objects using
try/finally to prevent file descriptor leaks
- Fix get_no_image() to properly close PIL Image object
- Fix api_log() to handle different JSON structures from clients
(some send {"log": {"logs_array": [...]}}, others send {"logs": [...]})
- Add error handling for file descriptor exhaustion in QuietWSGIServer
- Add error handling for file operations in persist_log, persist_client_data,
and persist_client_log_data functions
- Close HTTP session on server shutdown in handle_exit()
The root cause was PIL Image objects not being explicitly closed, which
caused file handles to accumulate over time until the OS limit was reached.
amalg
added a commit
to amalg/ha_addons
that referenced
this pull request
Feb 2, 2026
Updated submodule to use fork with fix for file descriptor exhaustion (OSError errno 24) that causes the server to become unresponsive. See: ohAnd/trmnlServer#7
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.
Summary
This PR addresses file descriptor exhaustion (OSError errno 24) that causes the TRMNL server to become unresponsive after extended operation.
Root Cause: PIL Image objects were not being explicitly closed, causing file handles to accumulate over time until the OS limit was reached.
Changes
requests.Sessionfor HTTP connection pooling instead of creating new connections for each requestadd_footer_to_image()to explicitly close PIL Image objects using try/finallyget_no_image()to properly close PIL Image objectapi_log()to handle different JSON structures from clients (some send{"log": {"logs_array": [...]}}, others send{"logs": [...]})QuietWSGIServerhandle_exit()Test Plan
Evidence
Before fix - server logs showed:
After fix - server remains stable without resource exhaustion.