Skip to content

Storage hangs without completing or errors when uploading or getting files in parallel #6194

Closed

Description

@jellynoone

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:

{"result":{"permit":true},"id":82,"status":"ok"}
{"context":{"path":"/databases/(default)/documents/..."},"action":"fetch_firestore_document","server_request_id":83}

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.

Originally posted by @jellynoone in #4918 (comment)

Activity

  1. jellynoone commented on Jul 28, 2023

    @jellynoone
    Author

    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:

    1. The test for this bug is incorrect
    2. The number of test files being downloaded at the same time should probably be increased

    Full reference to the test in question:

    emulatorOnly.it("serves content successfully when spammed with calls", async () => {
    const NUMBER_OF_FILES = 10;
    const allFileNames: string[] = [];
    for (let i = 0; i < NUMBER_OF_FILES; i++) {
    const fileName = TEST_FILE_NAME.concat(i.toString());
    allFileNames.push(fileName);
    await testBucket.upload(smallFilePath, { destination: fileName });
    }
    await signInToFirebaseAuth(page);
    const values: string[] = [];
    for (const singleFileName of allFileNames) {
    values.push(
    await page.evaluate((filename) => {
    return firebase.storage().ref(filename).getDownloadURL();
    }, singleFileName)
    );
    }
    expect(values.length).to.be.equal(10);
    });
    });

    The specifically possibly incorrect part:

    const values: string[] = [];
    for (const singleFileName of allFileNames) {
    values.push(
    await page.evaluate((filename) => {
    return firebase.storage().ref(filename).getDownloadURL();
    }, singleFileName)
    );
    }

    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:

            const promises: Promise<string>[] = [];
            for (const singleFileName of allFileNames) {
              values.push(page.evaluate((filename) => {
                return firebase.storage().ref(filename).getDownloadURL();
              }, singleFileName));
            }
            const values = Promise.all(promises);

    #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?

  2. jellynoone commented on Jul 31, 2023

    @jellynoone
    Author

    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??

  3. christhompsongoogle commented on Aug 1, 2023

    @christhompsongoogle
    Contributor

    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.

  4. christhompsongoogle commented on Aug 1, 2023

    @christhompsongoogle
    Contributor

    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.

  5. jellynoone commented on Aug 2, 2023

    @jellynoone
    Author

    @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:

    lock.acquire(synchonizationKey, (done) => {
    this._childprocess?.stdin?.write(serializedRequest + "\n");
    setTimeout(() => {
    done();
    }, 15);

    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.

  6. jellynoone commented on Aug 2, 2023

    @jellynoone
    Author

    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.

    I'll test with the --debug flag and come back with the results.

  7. jellynoone commented on Aug 2, 2023

    @jellynoone
    Author

    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.

  8. 2 remaining items

  9. removed their assignment
    on Jul 30, 2024
  10. transfer1992 commented on Mar 24, 2025

    @transfer1992

    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?

  11. loewj-reekon commented on May 28, 2025

    @loewj-reekon

    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.

  12. CambodianCoder commented on Aug 5, 2025

    @CambodianCoder

    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.

  13. added 2 commits that reference this issue on Jul 12, 2026
    3c9c73f
    b893d8a
  14. glorat commented on Jul 12, 2026

    @glorat

    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) => {
      const serializedRuntimeActionResponse = 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:

    {"result":{"permit":true},"id":1,"status":"ok"}
    {"result":{"permit":true},"id":2,"status":"ok"}
    

    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.

  15. added a commit that references this issue on Jul 28, 2026
    b34f512
  16. added a commit that references this issue on Aug 5, 2026
    0d89ccd
  17. added a commit that references this issue on Aug 16, 2026
    505ce75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions