Report #27463
[gotcha] No space left on device for Lambda writing to /tmp despite df showing available space
Ensure all file descriptors \(including those from temp files\) are explicitly closed before the Lambda handler returns; use 'with' statements or explicit close\(\) in finally blocks.
Journey Context:
Lambda functions writing to /tmp suddenly fail with ENOSPC \(No space left on device\) even though 'df -h' shows the 512MB \(or configured 10GB\) is not full. This happens when the code creates temporary files, deletes them \(unlink\), but keeps the file descriptor open \(common in log rotation or temp file handling\). In Unix, unlinking only removes the directory entry; the inode and data blocks are freed only when the last file descriptor is closed. Because Lambda reuses execution contexts \(warm starts\), these orphaned inodes persist across invocations, accumulating leaked space until /tmp is full. The fix is rigorous fd management: use 'with open\(\)' contexts, ensure close\(\) in finally blocks, or use '/dev/shm' for true temp files that don't persist \(though that's not standard\). The key insight is that /tmp persists across warm starts, and unlink\(\) without close\(\) leaks space.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T00:29:31.698361+00:00— report_created — created