Skip to content

Multiple rapid calls to Storage Emulator API causes some requests to hang/not get a response. #4768

Closed

Description

@indicava

[REQUIRED] Environment info

11.3.0

Ubuntu 20.04.3 LTS
Node v16.16.0

[REQUIRED] Test case


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Storage Emulator Bug</title>
</head>

<body>
    <input type="file" multiple id="file" />
    <input type="checkbox" id="production" />
    <label for="production">Production</label>
    <script type="module">
        import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.9.0/firebase-app.js'
        import { uploadBytes, connectStorageEmulator, getStorage, ref } from 'https://www.gstatic.com/firebasejs/9.9.0/firebase-storage.js'
        const firebaseConfig = {
            apiKey: "REMOVED",
            authDomain: "REMOVED",
            projectId: "REMOVED",
            storageBucket: "REMOVED",
            messagingSenderId: "REMOVED",
            appId: "REMOVED"
        };

        const app = initializeApp(firebaseConfig);
        document.getElementById("file").onchange = function (e) {
            const files = e.target.files
            for (let i = 0; i < files.length; i++) {

                const storage = getStorage();
                if (!(document.getElementById("production").checked)) connectStorageEmulator(storage, "localhost", 9199)

                const storageRef = ref(storage, files[i].name);

                uploadBytes(storageRef, files[i]).then((snapshot) => {
                    console.log('Uploaded a blob or file!');
                });
            }
        }
    </script>
</body>

</html>

[REQUIRED] Steps to reproduce

Upload multiple files (~8 or more) to Storage Emulator of size 3MB-4MB using Web SDK (code example above).

[REQUIRED] Expected behavior

All uploads should complete and get a valid response from the API

[REQUIRED] Actual behavior

Some requests hang, meaning a response is never returned from the Emulator API.

When this occurs the following message is displayed in the emulator console/firebase-debug.log (and no other messages at all):

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

sample firebase-debug.log:


[info] i  hosting: Serving hosting files from: dist {"metadata":{"emulator":{"name":"hosting"},"message":"Serving hosting files from: \u001b[1mdist\u001b[22m"}}
[info] ✔  hosting: Local server: http://127.0.0.1:5000 {"metadata":{"emulator":{"name":"hosting"},"message":"Local server: \u001b[4m\u001b[1mhttp://127.0.0.1:5000\u001b[22m\u001b[24m"}}
[debug] [2022-07-21T17:47:47.103Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: auto_download"}}
[debug] [2022-07-21T17:47:47.103Z] Ignoring unsupported arg: port {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: port"}}
[debug] [2022-07-21T17:47:47.104Z] Starting Emulator UI with command {"binary":"node","args":["/home/elad/.cache/firebase/emulators/ui-v1.8.1/server/server.js"],"optionalArgs":[],"joinArgs":false} {"metadata":{"emulator":{"name":"ui"},"message":"Starting Emulator UI with command {\"binary\":\"node\",\"args\":[\"/home/elad/.cache/firebase/emulators/ui-v1.8.1/server/server.js\"],\"optionalArgs\":[],\"joinArgs\":false}"}}
[info] i  ui: Emulator UI logging to ui-debug.log {"metadata":{"emulator":{"name":"ui"},"message":"Emulator UI logging to \u001b[1mui-debug.log\u001b[22m"}}
[debug] [2022-07-21T17:47:47.246Z] Web / API server started at 127.0.0.1:4000
 {"metadata":{"emulator":{"name":"ui"},"message":"Web / API server started at 127.0.0.1:4000\n"}}
[info] 
┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://127.0.0.1:4000                │
└─────────────────────────────────────────────────────────────┘

┌──────────┬────────────────┬───────────────────────────────┐
│ Emulator │ Host:Port      │ View in Emulator UI           │
├──────────┼────────────────┼───────────────────────────────┤
│ Hosting  │ 127.0.0.1:5000 │ n/a                           │
├──────────┼────────────────┼───────────────────────────────┤
│ Storage  │ 127.0.0.1:9199 │ http://127.0.0.1:4000/storage │
└──────────┴────────────────┴───────────────────────────────┘
  Emulator Hub running at 127.0.0.1:4400
  Other reserved ports: 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
 
[info] {"result":{"permit":true},"id":1,"status":"ok"}
{"result":{"permit":true},"id":2,"status":"ok"}
{"result":{"permit":true},"id":3,"status":"ok"}
{"result":{"permit":true},"id":4,"status":"ok"}
{"result":{"permit":true},"id":5,"status":"ok"} {"metadata":{"emulator":{"name":"storage"},"message":"{\"result\":{\"permit\":true},\"id\":1,\"status\":\"ok\"}\n{\"result\":{\"permit\":true},\"id\":2,\"status\":\"ok\"}\n{\"result\":{\"permit\":true},\"id\":3,\"status\":\"ok\"}\n{\"result\":{\"permit\":true},\"id\":4,\"status\":\"ok\"}\n{\"result\":{\"permit\":true},\"id\":5,\"status\":\"ok\"}"}}

Screenshot of Chrome dev tools showing hung requests:

image

My storage.rules file:


rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}

Activity

  1. phath9 commented on Jul 25, 2022

    @phath9

    Experience the same with a Flutter client. Using Future.await to send multiple uploads asynchronously caused the emulator to hang. When changed to synchronously sending uploads, the hang was not observed.

  2. lisajian commented on Jul 25, 2022

    @lisajian
    Contributor

    Hi @tonyjhuang - would you mind taking a look and/or reroute as appropriate? Thank you!

  3. tonyjhuang commented on Jul 29, 2022

    @tonyjhuang
    Contributor

    Duplicate of #3915, closing in favor of that issue

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