Skip to content
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

Server stops handling requests when requesting many files during initial startup #5448

Closed
7 tasks done
Artur- opened this issue Oct 27, 2021 · 3 comments · Fixed by #5452
Closed
7 tasks done

Server stops handling requests when requesting many files during initial startup #5448

Artur- opened this issue Oct 27, 2021 · 3 comments · Fixed by #5452

Comments

@Artur-
Copy link
Contributor

Artur- commented Oct 27, 2021

Describe the bug

When starting Vite in a given project, I see

Pre-bundling dependencies:
  construct-style-sheets-polyfill
  @vaadin/router
  @vaadin/vaadin-app-layout
  @vaadin/vaadin-lumo-styles/badge
  @vaadin/vaadin-tabs
  (...and 62 more)
(this will be run only when your dependencies or config have changed)

Then if I load a file (app-view.ts) that imports a lot of other files and do that many times over using e.g. curl http://localhost:3004/VAADIN/src/app-view.ts

I see this in Vite

4:52:46 PM [vite] new dependencies found: lit-vaadin-helpers, @vaadin/app-layout, @vaadin/app-layout/vaadin-drawer-toggle, @vaadin/button, @vaadin/combo-box, @vaadin/context-menu, @vaadin/details, @vaadin/dialog, @vaadin/notification, @vaadin/text-field, copy-to-clipboard, updating...
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-ZWWIBHNC.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-JQLAO6NM.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-SDCOPK4H.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-FIOBJAVO.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-5RUW3UMH.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-EO3SFW3O.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-Y4T4KCL3.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-K4KH3HS3.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-7URMQNOQ.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-JQBQZK7Q.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-CJI4KICL.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-QCO22J74.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-74BJK6OX.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-GVRVJBST.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-Y63HMMXH.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-LSOISA4A.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-6KKEGG5S.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-Z3WSW6FS.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-VS7UAYY2.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-B3TW43OM.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-4NYYVVIF.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-HKMYNPQ2.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-WO4PJIM6.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-W6URIUWJ.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-BFUOR7LA.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-2DBAW5ZD.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-O32BREKP.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-J7MWSVN7.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-KP7AFHWK.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-5GPX4IEB.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-B7JKNOZF.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-GYDCCW2D.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-EGG4AO3M.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-AZRPJPWH.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-BAZMUHGS.js?v=a23cff78.
4:52:46 PM [vite] Failed to load source map for /@fs/...projectFolder.../node_modules/.vite/chunk-ERFRXPKI.js?v=a23cff78.
4:52:48 PM [vite] ✨ dependencies updated, reloading page...

Requesting the same file again results in

4:54:52 PM [vite] new dependencies found: lit/directives/live.js, @vaadin/checkbox, @vaadin/item, @vaadin/list-box, @vaadin/select, lit/directives/class-map.js, @vaadin/text-area, array-union, uuid, downloadjs, lit/directives/repeat.js, @vaadin/custom-field, @vaadin/horizontal-layout, shepherd.js, @vaadin/radio-group, lit/directives/if-defined.js, @vaadin/tabs, @vaadin/grid, @vaadin/grid/vaadin-grid-tree-column.js, new-github-issue-url, updating...
4:54:53 PM [vite] ✨ dependencies updated, reloading page...

and the third time it finds even some more dependencies

Now if I do not wait for the steps to complete but instead start Vite and then fetch the file as

for a in `seq 1 10 `; do curl http://localhost:3004/VAADIN/src/app-view.ts ; done

then one of three things happens to each request:

  1. I get a version of the file
  2. I get Something unexpected happened while optimizing "/src/app-view.ts"<h1><p>The current page should have reloaded by now</p>
  3. The request just freezes for eternity

Might be that this does not cause problems in the browser as reloading the page cuts the request which are loading resources and the browser then tries again. However, in our setup we have a Java server between the browser and Vite (the Java server handles part of the application). The proxy will then be left with a lot of requests that are just hanging, waiting for Vite to respond. These requests then prevent other requests from being handled before the time out in the end as Vite never responds. If Vite just closed the connections, it would work fine.

Reproduction

Unfortunately the application where the problem reproduces cannot be shared and I have not been able to reproduce it in a standalone project. I am happy to debug it further if you have any pointers on how.

System Info

System:
    OS: macOS 11.6
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.27 GB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.11.0 - /usr/local/bin/node
    Yarn: 1.22.11 - /usr/local/bin/yarn
    npm: 8.0.0 - /usr/local/bin/npm
    Watchman: 2021.10.04.00 - /usr/local/bin/watchman
  Browsers:
    Brave Browser: 93.1.29.81
    Chrome: 95.0.4638.54
    Chrome Canary: 97.0.4683.0
    Firefox: 92.0.1
    Safari: 15.0
    Safari Technology Preview: 15.4
  npmPackages:
    vite: ^2.6.4 => 2.6.13

Used Package Manager

npm

Logs

No response

Validations

@Artur- Artur- changed the title Server stops handling requests when browser is loading many files during initial startup Server stops handling requests when requesting many files during initial startup Oct 27, 2021
@Artur-
Copy link
Contributor Author

Artur- commented Oct 27, 2021

What happens in the code is that

server._pendingReload = new Promise((r) => {

happily overwrites any existing _pendingReload with a new promise even though there might be current requests waiting for that _pendingReload to resolve. Thus the promise is never resolved for those clients and they remain waiting here
server._pendingReload.then(() =>

@patak-dev
Copy link
Member

Would you like to work on a PR for this @Artur- ?

Artur- added a commit to Artur-/vite that referenced this issue Oct 27, 2021
In case of this call sequence
1. registerMissingImport
2. a new incoming request
3. registerMissingImport

the request in step 2 will keep waiting indefinitely for a promise that will never resolve as step 3 overwrites the _pendingReload promise without resolving the previous one

Fixes vitejs#5448
Artur- added a commit to Artur-/vite that referenced this issue Oct 27, 2021
fix vitejs#5448)

In case of this call sequence
1. registerMissingImport
2. a new incoming request
3. registerMissingImport

the request in step 2 will keep waiting indefinitely for a promise that will never resolve as step 3 overwrites the _pendingReload promise without resolving the previous one

Fixes vitejs#5448
@Artur-
Copy link
Contributor Author

Artur- commented Oct 27, 2021

Sure, I created #5452

@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants