AsperforMias opened a new pull request, #3778:
URL: https://github.com/apache/dubbo-go/pull/3778
### Description
Fixes #3777
`(*serverRequest).UnmarshalJSON` unmarshals the request through a named
pointer type (`type req *serverRequest`). `encoding/json` v1 does not call
`UnmarshalJSON` on that type. `encoding/json` v2 does, so the method calls
itself until the runtime aborts with `fatal error: stack overflow`.
Severity: a jsonrpc server built with Go 1.27 or later crashes when it
decodes a request body into `serverRequest`. That is the normal JSON-RPC POST
path (`ReadHeader`). The crash is a runtime fatal error and cannot be
recovered. The process exits.
Scope: only `protocol/jsonrpc` server request decoding. This repository has
one `type Name *T` declaration, and it is this alias. The triple and dubbo
protocols do not use this method. Default Go 1.25 and Go 1.26 builds are
unaffected. Builds with `GOEXPERIMENT=jsonv2` are affected on older toolchains.
The same code is on `main` (`832124aa`) and `develop` (`97666ec`).
apache/dubbo-go-samples CI currently hits this crash because
apache/skywalking-eyes/header@main started installing Go 1.27 (CI fix PR to
samples will be opened separately). A backport to `main` may be wanted. This PR
targets `develop` only.
The fix gives the alias the struct type, which has the same fields and no
methods, and unmarshals into a pointer to that alias:
```go
type req serverRequest
if err := json.Unmarshal(raw, (*req)(r)); err != nil {
```
On json v1 this decodes the same fields. `TestServerRequestUnmarshalJSON`
passes on go1.25.0, and the value-alias form of the minimal pattern passes on
go1.25.0, go1.26.10, and go1.27.3 with `GOEXPERIMENT=nojsonv2`.
Upstream:
- https://github.com/golang/go/issues/75361 is open. On 2026-01-23 the Go
team decided to keep the v2 behavior and recommended `type X T` plus
`json.Unmarshal(b, (*X)(p))`.
- https://go.dev/cl/818760 is status NEW (uploaded 2026-08-20) and is not
merged.
- Go 1.27.3 has no `GODEBUG` switch for this. `GOEXPERIMENT=nojsonv2`
selects the old decoder. `go vet` from Go 1.27.3 exits 0 on the unfixed package.
- The same alias change was merged in
https://github.com/moby/moby/pull/53281 (2026-08-03) and
https://github.com/anchore/syft/pull/4748 (2026-04-10).
CI installs the Go version from `go.mod` (`go 1.25.0`) via
`.github/actions/setup-go`. Current unit tests do not compile this package with
Go 1.27.
Verification, `GOTOOLCHAIN=local`, darwin/arm64. Before the fix, `go test
-count=1 -timeout 3m -run TestServerRequestUnmarshalJSON ./protocol/jsonrpc/`:
- go1.25.0: `ok` (0.754s)
- go1.25.0 with `GOEXPERIMENT=jsonv2`: `fatal error: stack overflow` (1.511s)
- go1.27.3: `fatal error: stack overflow` (1.366s), `goroutine stack exceeds
1000000000-byte limit`
After the fix, `go test -count=1 -timeout 4m ./protocol/jsonrpc/...`:
- go1.25.0: `ok` (1.098s)
- go1.25.0 with `GOEXPERIMENT=jsonv2`: `ok` (1.081s)
- go1.27.3: `ok` (1.081s)
`go vet ./protocol/jsonrpc/...` exits 0 with go1.25.0 and with go1.27.3.
`make fmt` was run with Go 1.25.0 (`GOTOOLCHAIN=local`). It exited 0. `gofmt
-l` on tracked Go files printed nothing. The diff is limited to
`protocol/jsonrpc/json.go` and `protocol/jsonrpc/json_test.go`.
`go test -count=1 -timeout 15m ./...` was run with `GOTOOLCHAIN=local` on
darwin/arm64 for go1.25.0 and go1.27.3 in parallel. That is the root-module
command from `make test`. `make test` itself was not invoked: it writes one
shared `coverage.txt` and also tests `tools/dubbogo-cli`, so it cannot run
twice at once.
Both runs listed 187 packages with the same status: 128 `ok`, 58 with no
test files, and one failure. `protocol/jsonrpc` passed (go1.25.0 10.118s,
go1.27.3 10.599s). Neither log contains a stack overflow.
The only failing package on both toolchains is `config_center/zookeeper`,
with the same three tests:
- `TestGetPropertiesCacheUpdatedByWatch` (`impl_test.go:376`, condition
never satisfied)
- `TestRestartCallBackRestoresBusinessListener` (`impl_test.go:481`,
listener did not receive `"v2"`)
- `TestRestartCallBackRestoresBusinessListenerWhenCacheDisabled`
(`impl_test.go:529`, listener did not receive `"v2"`)
Both logs show the ZooKeeper client at `127.0.0.1:2181` disconnecting (`recv
loop terminated: EOF`). The same three tests failed the same way on unmodified
`develop` with go1.25.0. They are environment failures, not a result of this
change.
`make test` did not pass, so the checklist item below stays unchecked.
### Checklist
- [x] I confirm the target branch is `develop`
- [x] I have run `make fmt` to format my code
- [ ] I have run `make test` to run local tests
- [x] I have added tests that prove my fix is effective or that my feature
works
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]