Skip to content

Fix dangling GridFS stream - #1986

Open
alcaeus wants to merge 1 commit into
mongodb:v2.4from
alcaeus:fix-dangling-gridfs-stream
Open

alcaeus wants to merge 1 commit into
mongodb:v2.4from
alcaeus:fix-dangling-gridfs-stream

Conversation

@alcaeus

@alcaeus alcaeus commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a rare issue with GridFS uploads. When uploading from a stream, Bucket::uploadFromStream relies on the $destination file pointer to go out of scope and closed, which then triggers the write to the databases. However, Xdebug can end up holding an additional reference to this file pointer, which then causes the write to be skipped.

To fix this, we wrap the entire write/return logic in a try-finally block to ensure the file pointer gets closed explicitly instead of relying on garbage collection to handle it for us.

Note: I haven't added a test for this as it is hard to reproduce. This appeared locally in my Doctrine ODM test suite as I run with Xdebug in develop mode by default. I confirmed locally that this patch fixes the failures I encountered.

@alcaeus
alcaeus requested a review from a team as a code owner September 16, 2026 05:40
@alcaeus
alcaeus requested a review from GromNaN September 16, 2026 05:40
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@alcaeus
alcaeus force-pushed the fix-dangling-gridfs-stream branch from 47eed32 to f9b1dc5 Compare September 16, 2026 05:47
@alcaeus

alcaeus commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Test failures are unrelated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants