Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
xpcallwith an error handler can hang or report the wrong error, because the handler is stored as aframe-relative stack index and then read as an absolute one:
When the call happens inside a running chunk (
callInfo.function != 0), the two disagree: the handleris looked up at the wrong stack slot. Minimal reproduction:
panic: test timed out after 10s— unbounded recursionre-entering the outermost chunk), or, with a test that pre-fills the slot, fails with
handler result: error in error handling;false, "H:...:1: x".The change
Store the handler as an absolute index by adding the current frame base:
One line.
pcall(errorFunction == 0) and the top-level hostProtectedCall(
callInfo.function == 0) are unaffected by construction.Verification
go test -vet=off -run TestXPCall -v -count=1:main+ only the new test): FAIL withhandler result: error in error handling;git apply patch.diff,apply --checkclean): both tests pass;go test -vet=off ./...: ok.The regression test pre-fills the stale slot with a non-callable value (with a comment explaining why)
so the wrong index fails fast instead of hanging for minutes.
Dedupe: searched
xpcall/ error handler / hang / recursion on the repo's issues and PRs — no match.Shopify CLA has been signed.