-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Problem
Enclaves can experience file descriptor exhaustion under heavy load, and unbuffered output to vsock logging can cause delays or incomplete log delivery.
Solution
- Increase file descriptor limits to prevent exhaustion
- Add line buffering for socat output to ensure timely log delivery
- Monitor file descriptor usage to detect potential issues
Code Changes in entrypoint.sh
# 1. Increase file descriptor limits (add after setting APP_MODE)
# Increase file descriptor limits to prevent socket exhaustion
ulimit -n 65536
log "File descriptor limit set to: $(ulimit -n)"
# 2. Add buffering to socat output (replace the exec redirect line)
# Redirect all output to the logging script via VSOCK with buffering
# Use stdbuf to line-buffer output for timely delivery
exec > >(stdbuf -oL socat -u - VSOCK-CONNECT:3:8011) 2>&1
# 3. Add file descriptor monitoring (add before starting the main application)
# Start file descriptor monitoring in background
(
while true; do
sleep 300 # Check every 5 minutes
FD_COUNT=$(ls /proc/*/fd 2>/dev/null | wc -l)
log "File descriptors in use: $FD_COUNT"
if [ "$FD_COUNT" -gt 50000 ]; then
log "WARNING: High file descriptor usage: $FD_COUNT"
fi
done
) &Benefits
- Prevents resource exhaustion: 65536 file descriptor limit provides ample headroom
- Reliable logging: Line buffering ensures logs are delivered promptly
- Early warning system: Monitoring alerts before hitting limits
- Better observability: Track resource usage over time
Testing
- Verify limit with
ulimit -ninside enclave - Monitor FD usage in logs every 5 minutes
- Confirm logs appear immediately (not delayed/batched)
- Test under load to ensure no "too many open files" errors
Impact
Critical for production stability - prevents service outages due to resource exhaustion and ensures complete log visibility for debugging issues.
Metadata
Metadata
Assignees
Labels
No labels