Skip to content

fix: return an error instead of panicking when scanning JSON into an unaddressable value - #1393

Open
Yusufihsangorgel wants to merge 1 commit into
uptrace:masterfrom
Yusufihsangorgel:fix/scanjson-unaddressable
Open

fix: return an error instead of panicking when scanning JSON into an unaddressable value#1393
Yusufihsangorgel wants to merge 1 commit into
uptrace:masterfrom
Yusufihsangorgel:fix/scanjson-unaddressable

Conversation

@Yusufihsangorgel

Copy link
Copy Markdown
Contributor

Fixes #1306

Scanning a JSONB column into a non-nil any field routes through scanJSONIntoInterface, which dispatches on the interface element. That element is not addressable, so scanJSON panicked on dest.Addr(), and with the reporter's setup the panic left the connection idle in transaction and the query blocked.

Following the suggestion in the issue, the JSON scan paths (scanJSON, scanJSONUseNumber, and the interface dispatch) now pre-check CanAddr and return a bun: Scan(nonaddressable ...) error early instead of panicking, mirroring how database/sql reports Scan(nonsettable ...).

Two tests: the regression case (non-nil interface, previously a panic, now an error and no panic) and the addressable map path to pin that normal JSON scanning is unaffected. go test ./... on the root module passes.

…unaddressable value

A non-nil interface field routes the scan to the element value, which is not
addressable, so scanJSON panicked on dest.Addr() and the connection was left
in idle-in-transaction. The JSON scan paths now pre-check CanAddr and fail
with an error, as suggested in uptrace#1306.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic in scanJSON causes deadlock

1 participant