Skip to content

Memory leak in service-worker #42

Description

@mindplay-dk

hi,

I plan on using this script to download very large files, so I set up a quick test-project to try it out.

https://github.com/mindplay-dk/downzip/tree/original-downzip

in the files folder, I have 10 files of about 0.46 GB each, and as you can see, I'm zipping and downloading them all - the idea here was just to see if this would work for over 4 GB of files, which it actually does. 🙂👍

it appears there's a memory issue though - while I'm downloading 4.6GB of files, the service worker appears to eat up 4.6GB of RAM, as you can see in this screen recording:

Animation

(for the record, the progress events you see in this recording is from this fork, which has a few extra features - I did test with your original package as well, which is what I'm using in the repo I linked to above, and it does have the same issue, I just didn't bother with a second screen recording.)

also, as you can see, it does not appear to really be streaming (?) so much as buffering the whole thing in the service worker - it appears to work up to the full 4.6GB of memory usage before the download really begins. this is probably a related issue. (and this is true of both your version and that fork as well.)

what's worse, memory appears to remain allocated after the download finishes - sometimes all of it, sometimes about half, sometimes for several minutes after closing the window. I suppose this could just be how Chrome operates service-workers? no idea.

I'm using latest Chrome on Win 11 Pro: Version 120.0.6099.71 (Official Build) (64-bit).

this all seemed rather odd, so I decided to give Firefox a go as well.

in Firefox, the downloads begin immediately - there's no delay, like there is in Chrome.

however, the downloads do not complete - they appear to randomly hang after 5-10 seconds of downloading:

image

similarly, memory usage does appear to climb while downloading, to about the same as amount of memory as the amount of the download that completes before it hangs - so the likely explanation is Firefox hitting the service-worker with some sort of memory usage limit designed to keep service-workers from eating all memory? however, there's no indication of any error in the debugger - and the downloads stall, forever, they're never canceled.

again, this is with Firefox on Win 11 Pro: 120.0.1 (64-bit).

just for completeness, I also gave Edge a shot - as you might expect, the experience is the same as in Chrome.

returning to Chrome, I also attempted to profile memory usage - oddly, if the memory profiler is running, memory will get freed immediately after the download, much sooner than without devtools... as you can see though, it is clearly allocating all the memory while the service-worker is downloading, before the host browser actually begins downloading the zip stream:

screenrecording

that's all I have right now - I will get back to you if I uncover anymore clues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions