You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Storage hangs without completing or errors when uploading or getting files in parallel #6194
Hi, @abhis3.
I'm still experiencing this issue, although, I should add it doesn't happen all that consistantly.
Here are the following specs:
Device: MacBook Pro (Retina, 13-inch, Mid 2014)
OS: macOS Big Sur, 11.7.8
Firebase tools: [email protected]
Additional context
The error doesn't just happen when uploading many files but also when downloading many of them in parallel, for instance, in context of a messaging application this would be when downloading in-chat media, like images or videos.
On my end, if I try to download sometimes 30 or sometimes more images, but at around 60 the failure rate is almost consistant. At the same time, I get the following output in the command line, where the emulators are run:
The images themselves are at average between 300kb - 500kb large.
I'm running into this problem when running a Flutter application, where a call writeToFile for the desired images, more or less so independent of one another i.e. it is coincidental that they are called in parallel as this depends on the images found on the particular screen.
I'm reposting my comment in the linked issue since I'm still experiencing it. I'm also attaching my other responses to that issue in hopes of being helpful:
#4918 (comment)
I also took a look at: dec8a3f and I think I noticed a few things could be improved:
The test for this bug is incorrect
The number of test files being downloaded at the same time should probably be increased
If we look at the test case, we see that the call to getDownloadURL is actually sequential because we are awaiting the await page.evaluate call. Meaning, we already get the result back before issuing a new getDownloadUrl.
I think the values retrieval here in the test should be rewritten as:
#4918 (comment)
I also have an additional question about the error itself. It seems that somewhere the emulator pipes the result to the wrong output i.e. to the terminal and not to the emulator. This then seems to deadlock other promises, since they are waiting for a previous operation to complete, and it is waiting for a result that was passed to a different consumer. Is this analysis correct?
I would also like to add that I'm using security rules. Perhaps the evaluation of those is what ends up delaying the response to the point of deadlock??
@christhompsongoogle Thank you for the update. I'm not entirely aware of how the page.evaluate call works but does it also evaluate more complex security rules?
For instance, with the project I'm experiencing this issue, I make a call to the firestore emulator to get the information about the document and validate the user's write and access permissions.
If page.evaluate does not do this, I suspect this might be why the bug isn't hit. In other words, I think the evaluation of the rules is fast enough that it doesn't hit the timeout:
This is mostly just speculation on my part, as I'm not deeply aware of how the internals here work. But it seems to me that this might be the reason since the bug does not always occur, which speaks to me of a timing issue.
I tried testing with the --debug flag and could not reproduce the issue, but I could still reproduce it with the regular run. Does the --debug flag also make all calls sequential and not parallel similar to how --inspect-functions does for the functions emulator? If that is the case then this might be the reason why I'm unable to reproduce the issue.
As noted in my first response, the log also includes: {"context":{"path":"/databases/(default)/documents/..."},"action":"fetch_firestore_document","server_request_id":297}
Which I assume is a log about a firestore get call in the security rules evaluation.
This issue breaks local development for any app that relies on Firebase Storage. We're experiencing hangs on nearly every file upload during development, with requests stuck in a pending state until the emulator is restarted. The behavior makes the Storage emulator effectively unusable. Thanks for the hard work. Hoping this gets unblocked soon.
My team is encountering this same issue. Would be nice to have #6615 from @benjaminpetersen merged if that fixes the issue. Looks like the latest comment there is requesting test cases. One might be able to get some test cases pretty quickly using an AI code editor if time/resources are a constraint.
We tracked this down to a stdout framing bug in the Storage rules runtime, and
it explains why it's timing-/size-/concurrency-dependent and hard to reproduce
on demand.
Root cause. The Storage emulator delegates rule evaluation to a Java
subprocess that writes one JSON response per line to stdout. The handler in src/emulator/storage/rules/runtime.ts parses each raw "data" chunk with a
single JSON.parse:
this._childprocess.stdout?.on("data",(buf)=>{constserializedRuntimeActionResponse=buf.toString("utf-8").trim();
...
rap=JSON.parse(serializedRuntimeActionResponse);// throws on 2+ responses
Node stream "data" events don't preserve message boundaries. Under
concurrency two or more responses land in one chunk:
JSON.parse throws on the concatenation, the error is caught and logged at
INFO, and the handler returns — so every response in that chunk is dropped
and the requests awaiting those ids never resolve. That's the hang. (A single
response split across two chunks fails the same way.) Bigger files and more
concurrent requests widen the window, which matches the repros on this thread
and in #6865.
You can see it directly: on a wedged run the dropped responses show up in the
logs as bare {"result":...,"id":N,...} lines — those are exactly the requests
that then hang, because their handlers were never called.
Fix. Frame the stream on newlines and buffer the incomplete trailing line
across chunks, instead of JSON.parse-ing whole chunks. The ~15ms per-request
write delay added for #3915 was a workaround for this same bug (it slowed writes
so responses were less likely to batch); with correct framing it's no longer
needed.
I've opened #10792 with the framing fix, plus unit tests that fail against the
current per-chunk parse and pass with it (covering both the batched and the
split-across-chunk cases). A prior PR, #6615, independently reached the same
root cause but stalled on the CLA and missing tests. Verified end-to-end: 25
concurrent 1.5 MB uploads go from 23/25 completing (2 hung past a 30s watchdog)
on current main to all completing in well under a second.
Activity
jellynoone commentedon Jul 28, 2023
I'm reposting my comment in the linked issue since I'm still experiencing it. I'm also attaching my other responses to that issue in hopes of being helpful:
#4918 (comment)
I also took a look at: dec8a3f and I think I noticed a few things could be improved:
Full reference to the test in question:
firebase-tools/scripts/storage-emulator-integration/conformance/firebase-js-sdk.test.ts
Lines 492 to 513 in 8e3e216
The specifically possibly incorrect part:
firebase-tools/scripts/storage-emulator-integration/conformance/firebase-js-sdk.test.ts
Lines 502 to 509 in 8e3e216
If we look at the test case, we see that the call to
getDownloadURLis actually sequential because we are awaiting theawait page.evaluatecall. Meaning, we already get the result back before issuing a newgetDownloadUrl.I think the values retrieval here in the test should be rewritten as:
#4918 (comment)
I also have an additional question about the error itself. It seems that somewhere the emulator pipes the result to the wrong output i.e. to the terminal and not to the emulator. This then seems to deadlock other promises, since they are waiting for a previous operation to complete, and it is waiting for a result that was passed to a different consumer. Is this analysis correct?
jellynoone commentedon Jul 31, 2023
I would also like to add that I'm using security rules. Perhaps the evaluation of those is what ends up delaying the response to the point of deadlock??
christhompsongoogle commentedon Aug 1, 2023
Thank you @jellynoone for your detailed analysis here. I'll update the test and see if we can get more information on the failure mode here.
christhompsongoogle commentedon Aug 1, 2023
I added a test in #6209 but wasn't able to reproduce the issue, up to 200 files and 2MB in size.
@jellynoone if you launch the emulator with the --debug flag that might help get more information on this bug.
jellynoone commentedon Aug 2, 2023
@christhompsongoogle Thank you for the update. I'm not entirely aware of how the
page.evaluatecall works but does it also evaluate more complex security rules?For instance, with the project I'm experiencing this issue, I make a call to the firestore emulator to get the information about the document and validate the user's write and access permissions.
If
page.evaluatedoes not do this, I suspect this might be why the bug isn't hit. In other words, I think the evaluation of the rules is fast enough that it doesn't hit the timeout:firebase-tools/src/emulator/storage/rules/runtime.ts
Lines 274 to 278 in 1a78f64
This is mostly just speculation on my part, as I'm not deeply aware of how the internals here work. But it seems to me that this might be the reason since the bug does not always occur, which speaks to me of a timing issue.
jellynoone commentedon Aug 2, 2023
I'll test with the --debug flag and come back with the results.
jellynoone commentedon Aug 2, 2023
I tried testing with the --debug flag and could not reproduce the issue, but I could still reproduce it with the regular run. Does the --debug flag also make all calls sequential and not parallel similar to how --inspect-functions does for the functions emulator? If that is the case then this might be the reason why I'm unable to reproduce the issue.
As noted in my first response, the log also includes:
{"context":{"path":"/databases/(default)/documents/..."},"action":"fetch_firestore_document","server_request_id":297}Which I assume is a log about a firestore get call in the security rules evaluation.
2 remaining items
transfer1992 commentedon Mar 24, 2025
I am still experiencing this issue in March 2025. I can see that the proposed MR from @benjaminpetersen was never merged. Is there a path forward?
loewj-reekon commentedon May 28, 2025
This issue breaks local development for any app that relies on Firebase Storage. We're experiencing hangs on nearly every file upload during development, with requests stuck in a pending state until the emulator is restarted. The behavior makes the Storage emulator effectively unusable. Thanks for the hard work. Hoping this gets unblocked soon.
CambodianCoder commentedon Aug 5, 2025
My team is encountering this same issue. Would be nice to have #6615 from @benjaminpetersen merged if that fixes the issue. Looks like the latest comment there is requesting test cases. One might be able to get some test cases pretty quickly using an AI code editor if time/resources are a constraint.
fix(emulator): frame Storage rules runtime stdout on newlines
fix(emulator): Storage emulator hangs under concurrent requests
glorat commentedon Jul 12, 2026
We tracked this down to a stdout framing bug in the Storage rules runtime, and
it explains why it's timing-/size-/concurrency-dependent and hard to reproduce
on demand.
Root cause. The Storage emulator delegates rule evaluation to a Java
subprocess that writes one JSON response per line to stdout. The handler in
src/emulator/storage/rules/runtime.tsparses each raw"data"chunk with asingle
JSON.parse:Node stream
"data"events don't preserve message boundaries. Underconcurrency two or more responses land in one chunk:
JSON.parsethrows on the concatenation, the error is caught and logged atINFO, and the handler
returns — so every response in that chunk is droppedand the requests awaiting those ids never resolve. That's the hang. (A single
response split across two chunks fails the same way.) Bigger files and more
concurrent requests widen the window, which matches the repros on this thread
and in #6865.
You can see it directly: on a wedged run the dropped responses show up in the
logs as bare
{"result":...,"id":N,...}lines — those are exactly the requeststhat then hang, because their handlers were never called.
Fix. Frame the stream on newlines and buffer the incomplete trailing line
across chunks, instead of
JSON.parse-ing whole chunks. The ~15ms per-requestwrite delay added for #3915 was a workaround for this same bug (it slowed writes
so responses were less likely to batch); with correct framing it's no longer
needed.
I've opened #10792 with the framing fix, plus unit tests that fail against the
current per-chunk parse and pass with it (covering both the batched and the
split-across-chunk cases). A prior PR, #6615, independently reached the same
root cause but stalled on the CLA and missing tests. Verified end-to-end: 25
concurrent 1.5 MB uploads go from 23/25 completing (2 hung past a 30s watchdog)
on current
mainto all completing in well under a second.fix(emulator): Storage emulator hangs under concurrent requests (#10852)
fix(emulator): Storage emulator hangs under concurrent requests (#10852)
fix(emulator): Storage emulator hangs under concurrent requests (fire…