Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Race-condition in checking existence of service-worker.js #1089

Open
@MrSrsen

Description

@MrSrsen

Describe the bug

I think that there is probably some racing condition in Sapper compiler.
In some cases Sapper compiler is not correctly detecting existence of service-worker.js file when compiling app in dev mode.

This line 24 ...

const has_service_worker = fs.existsSync(path.join(build_dir, 'service-worker.js'));

in /runtime/src/server/middleware/get_page_handler.ts is not working as it should. existsSync is returning false but when I add timeout with the same code after that line then it's returning true.

As consequence of this issue, there is not link to service-worker in the footer of the index.html file.

To Reproduce

I don't know how exactly reproduce it in some minimum possible amount of code. It can by some specific edge-case that is occurring only in my environment.

In my case it's occurring only in dev mode and when i change value in my config that is turning on/off my custom roll-up plugin (issue is occurring when it's turned on).

Expected behavior
Existence of service-worker.js is checked correctly.

Severity

  • medium if you need functioning service-worker in dev mode for debugging purposes
  • low if you don't

Additional context

My possible hotfix was to add these lines to /runtime/src/server/middleware/get_page_handler.ts

while (!fs.existsSync(path.join(build_dir, 'service-worker.js'))) {
	continue;
}

This is obviously not long-term or universal solution because service-worker can legitimately not exist if you turn it off in configuration.

Additional info

I am using Sapper code from master branch from commit b1c4585.

Compilation is running in Docker image mhart/alpine-node:13.1.0 on Ubuntu 18.04.4 TLS.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions