Skip to content

Race condition when restarting server #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Rich-Harris opened this issue Apr 8, 2023 · 4 comments · Fixed by #363
Closed

Race condition when restarting server #341

Rich-Harris opened this issue Apr 8, 2023 · 4 comments · Fixed by #363

Comments

@Rich-Harris
Copy link
Member

Not quite sure what's going on here, but rapidly editing an .env file seems to cause something to get stuck:

https://learn.svelte.dev/tutorial/env-static-public

Screen.Recording.2023-04-08.at.10.49.09.AM.mov
@tomoam
Copy link
Contributor

tomoam commented Apr 10, 2023

Vite restarts on .env file update.
https://github.com/vitejs/vite/blob/09350c69ada6a43b26241b99a0d4f8aa4283ade2/packages/vite/src/node/server/hmr.ts#L44-L75

So we might have to wait for server-ready when updating the .env file as well.

@Rich-Harris
Copy link
Member Author

I wonder if we need something more sophisticated than a simple queue of operations, i.e. keep track of what state the filesystem should be in but discard any intermediate changes, so that b and c are rolled into d:

                   idle

file update (a) -> apply (a) (wait for chokidar, or serve-ready)
                    |
file update (b)     |
                    |
file update (c)     |
                    |
file update (d)     |
                    v

                   apply (d)
                    |
                    |
                    |
                    v

file update (e) -> apply (e)

At the moment it's more like this

                   idle

file update (a) -> apply (a) (wait for chokidar, or serve-ready)
                    |
file update (b)     |
                    |
file update (c)     |
                    |
file update (d)     |
                    v

                   apply (b)
                    |
                    |
                    |
                    v

file update (e) -> apply (c)
                    |
                    |
                    |
                    v

                   apply (d)
                    |
                    |
                    |
                    v

                   apply (e)

@tomoam
Copy link
Contributor

tomoam commented Apr 11, 2023

I agree completely.
I tried to implement waiting for server-ready in the update method when updating .env and found out why that mechanism is needed.

@tomoam
Copy link
Contributor

tomoam commented Apr 13, 2023

Related to this, in rare cases, there seems to be an error when moving from an exercise with .env file to one without .env file.

env-file-removed_720.mov

dummdidumm pushed a commit that referenced this issue May 11, 2023
Fixes #341

This PR fixes the behavior of .env files when they are updated and when they are deleted, and includes the mechanism shown in #341
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants