fix: don't render nil JsVar Ptr through value-receiver callbacks (#196)#208
Merged
Conversation
Rendering a JsVar bound to a nil pointer passed the typed-nil Ptr to Element.ApplyGetter, which saw a non-nil interface and invoked a value-receiver tag.TagGetter (or InitHandler) through the nil pointer, panicking. Because the write lock was released with a bare Unlock rather than a deferred one, the panic unwound past it and left the shared locker held forever, stalling every goroutine sharing that state. Extract the render-time critical section into renderSnapshot, which holds the write lock under a deferred unlock and skips the bound-value getter and init callbacks when Ptr is nil. A nil Ptr now renders with no initial data and no bound-value tag, as NewJsVar documents, and a panic from a supported callback or from marshaling can no longer leak the lock. Fixes #196
linkdata
marked this pull request as ready for review
July 21, 2026 20:26
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.
Summary
Fixes #196. Rendering a
JsVarbound to a nil pointer could panic and then permanently retain the shared application lock.JawsRenderpassed the typed-nilPtrtoElement.ApplyGetter. Because a typed-nil pointer is a non-nil interface,ApplyGetterrecognizedtag.TagGetterand called its value-receiverJawsGetTagthrough the nil pointer, causing a runtime panic. The write lock was released with a bareUnlock(not a deferred one), so the panic unwound past it and left the locker held forever — stalling every goroutine sharing that application state.Fix
renderSnapshot, which holds the write lock under adefer Unlock(). A panic from a supported bound-value callback or from marshaling can no longer leak the lock.Ptris nil, skip the bound-value getter/init callbacks and omit the initial data — the behaviorNewJsVaralready documents ("reads return the zero value, rendering omits the initial data").Behavior for a non-nil
Ptris unchanged (samegettervalue passed toApplyGetter, same lock scope coveringApplyGetter+ marshal so the serialized value stays consistent with the dirty tag).Tests
Two regression tests, both verified to fail on the pre-fix code and pass after:
TestJsVar_RenderNilPointerWithTagGetterDoesNotLeakLock— the exact scenario from Rendering a nil JsVar pointer can panic and permanently retain its lock #196 (nil pointer to a type with a value-receiverJawsGetTag); asserts no panic, lock released, and nodata-jawsdata.TestJsVar_RenderMarshalPanicDoesNotLeakLock— a bound value whoseMarshalJSONpanics; asserts the panic propagates but the lock is still released.go test -race ./...passes across the module;go vet,gofmt, andstaticcheckare clean on the touched files.