#23726: fix(resilience): destroy write streams on download errors
commands
size: XS
Cluster:
Error Handling and Memory Management
## Summary
- Problem: Write streams created during media downloads and signal-cli installation are not explicitly destroyed on error paths (size limit exceeded, pipeline failure), potentially leaving file handles open
- Why it matters: Leaked file handles can accumulate over time, leading to EMFILE errors or inaccessible temporary files
- What changed: Added explicit `out.destroy()` calls on error paths in media store download and signal-cli installer
- What did NOT change: Happy-path download behavior is identical
## Change Type
- [x] Bug fix
## Scope
- [x] Gateway / orchestration
- [x] Integrations
## Security Impact
- New permissions/capabilities? No
- Secrets/tokens handling changed? No
- New/changed network calls? No
- Command/tool execution surface changed? No
- Data access scope changed? No
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added `out.destroy()` calls to properly clean up write streams when download errors occur in both media store and signal-cli installer.
- `src/commands/signal-install.ts`: Complete fix with both stream destruction and file cleanup via `fsUnlink`
- `src/media/store.ts`: Only added stream destruction on size limit exceeded path, missing file cleanup on pipeline failure
The fix in `signal-install.ts` is complete and follows the correct pattern. However, `store.ts` needs the same file cleanup pattern in the pipeline catch handler (line 196) to prevent leaked partial files when downloads fail.
<h3>Confidence Score: 3/5</h3>
- This PR partially addresses the file handle leak issue but leaves one error path without proper cleanup
- The fix correctly addresses the write stream cleanup issue in `signal-install.ts` with both `out.destroy()` and file cleanup. However, `store.ts` only adds `out.destroy()` on the size limit check but doesn't clean up the partial file in the pipeline catch handler, creating an incomplete fix that still allows file leaks on download errors
- Pay close attention to `src/media/store.ts` - the pipeline catch handler needs file cleanup logic
<sub>Last reviewed commit: c748aff</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#20022: Fix temp file leak on media download failure
by Clawborn · 2026-02-18
70.9%
#17816: Fix media store cleanup ignoring subdirectories (e.g. inbound)
by Clawborn · 2026-02-16
70.3%
#6273: fix: handle EPIPE errors gracefully in daemon operations
by batumilove · 2026-02-01
69.3%
#17243: fix(telegram): catch getFile network failures to prevent gateway cr...
by robbyczgw-cla · 2026-02-15
68.7%
#9214: Fix: EPIPE exception in systemd service operations
by vishaltandale00 · 2026-02-05
68.7%
#22540: fix(signal): preserve original filename in outbound attachments
by lailoo · 2026-02-21
68.5%
#20479: fix(slack): keep replies flowing for oversized file uploads
by olyashok · 2026-02-19
68.0%
#17630: Fix LINE media temp files accumulating in os.tmpdir
by Clawborn · 2026-02-16
67.9%
#16990: fix(media): strip auth headers on cross-origin redirect in download...
by AI-Reviewer-QS · 2026-02-15
67.7%
#17943: fix: use 0o644 for inbound media files to allow sandbox read access
by zerone0x · 2026-02-16
67.6%