fix(dev): increase default session memory limit in HTTPS dev server to prevent disconnections on large projects. #6207
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In projects with a particularly large number of modules, some requests to the dev server will fail when the server is under heavy load. Which requests fail is nondeterministic, but some of them always will. It looks like this:
Here's a repro. Unfortunately, I couldn't do this in StackBlitz -- when I tried to run it there, I couldn't even get the app to start. I'm assuming that's because this involves intentionally thrashing the filesystem and StackBlitz isn't optimized for that kind of fs access, but I don't really know.
Additional context
When I had this problem with my own app, I did a bunch of research on the
502 ENHANCE_YOUR_CALM
error that I was seeing in my terminal output. I eventually tracked it to nghttp2, the library Node uses to implement HTTP/2 support. This now-closed issue in Node itself gave me a clue as to what was going on. Apparently the error message is an anti-DDOS mechanism -- in the case of the now-fixed bug, the memory used by requests wasn't getting released.The default value for this limit is 10MB. I guessed that it might just be too small for a large-ish Vite project, so after seeing how the options get passed to
createSecureServer
, I bumped it up in my own project by passinghttps: { maxSessionMemory: 1000 }
in myvite.config.ts
, and this seemed to solve the problem consistently.100
also seemed to work, but it doesn't for this repro.Admittedly, the repro is absolutely bonkers. My real project loads ~1800 modules (we're working on code-splitting, but we did some things that inadvertently made that difficult, so it'll take a while 😬 ) but pulls down nowhere near as much data as the repro does. I'm not sure what a reasonable limit is, or what the dangers of bumping the default value might be (will it affect SSR?), so I'm curious what you all think about that. It also seems like something that should probably be configurable, but I had a bit of trouble trying to add it to the allowed types -- the option in question comes from
SessionOptions
, which doesn't make it into the set of allowed options as considered by Vite for reasons I haven't figured out yet.Also, if you'd like me to make my repro into a test, let me know! I wasn't sure if this sort of heavyweight thing was appropriate for the test suite, but happy to add it if it is.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).