fix(grpc): avoid nil conn panic when close races asyncInvoke - #6247
Draft
cursor[bot] wants to merge 2 commits into
Draft
fix(grpc): avoid nil conn panic when close races asyncInvoke#6247cursor[bot] wants to merge 2 commits into
cursor[bot] wants to merge 2 commits into
Conversation
Capture the gRPC connection before spawning the AsyncInvoke goroutine so client.close() cannot nil c.conn out from under Invoke and crash the process with a nil pointer dereference. Closes a user-facing crash trigger: asyncInvoke() followed by close() before the promise settles. Co-authored-by: Inanc Gumus <github@inanc.io>
Rely on the event loop waiting for the promise to settle; either fulfillment or rejection after close is acceptable. The regression is absence of a nil-conn panic. Co-authored-by: Inanc Gumus <github@inanc.io>
|
|
8 tasks
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?
Capture the gRPC connection before spawning the
AsyncInvokegoroutine soclient.close()cannot nilc.connout from underInvoke.Why?
AsyncInvokecheckedc.conn != nilon the VU event loop, then launched a goroutine that calledc.conn.Invoke(...). As soon asasyncInvoke()returned, JS could callclient.close(), which setsc.conn = nil. When the goroutine then ran, it paniced:Trigger:
Impact: process crash (SIGSEGV) on a documented API combination. Independent of the grpc-go v1.83.0 bump (#6240); the nil is k6's
Client.connfield.Using a closed-but-non-nil connection returns a gRPC error instead of panicking.
Checklist
make check) and all pass. (Focused:go test -raceon./internal/js/modules/k6/grpc/,go vet.)Checklist: Documentation (only for k6 maintainers and if relevant)
Related PR(s)/Issue(s)
k6/ws)Validation
grpcext.(*Conn).Invoke(0x0)before the fixTestAsyncInvokeCloseDoesNotPanicpasses under-race -count=5after the fixgo test -race ./internal/js/modules/k6/grpc/ -run 'TestClient$|TestAsyncInvoke'passes