Fix code_cache = "off" crash in cqueues server by initializing module_reset lazily
#809
+4
−2
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.
Summary
When running Lapis with the cqueues server and
code_cache = "off", the server can crash on the second (and subsequent) request with errors coming from lua-http/cqueues such as:This PR changes
lapis/cmd/cqueues.moon(and the generated.lua) to initializemodule_reset()lazily on the first stream, instead of eagerly at server startup.Root cause
module_reset()captures a “keep” snapshot ofpackage.loadedat the moment it’s created. When it’s created eagerly, the keep snapshot may not include all runtime server modules (probablyhttp.*andcqueues.*), which are later loaded as the server begins handling requests.With
code_cache = "off",reset()then clears modules that should not be reloaded. This can cause lua-http / cqueues modules to be re-required multiple times and re-applysocket.interpose(...)repeatedly, resulting in layered wrappers and mismatched return values (e.g.whybecomingnilor a string). Those values eventually hitce.strerror(why)/seterror(..., why)and crash the process.Reproduction
I'm providing an example project which reproduces the issue: https://github.com/39george/cqueues-reset-bug
Notes
I tried to set config parameter
code_cache = "app_only", but it fails too with another error: