AsperforMias opened a new issue, #3777:
URL: https://github.com/apache/dubbo-go/issues/3777
### What happened?
Expected: a jsonrpc server decodes a JSON-RPC request and continues handling
it.
Actual: `(*serverRequest).UnmarshalJSON` calls itself until the process
aborts.
Error:
```
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow
```
The repeating frame is `protocol/jsonrpc.(*serverRequest).UnmarshalJSON`,
reached from `(*ServerCodec).ReadHeader` (`json.Unmarshal` into
`serverRequest`). This is a runtime fatal error. `recover` does not catch it,
and the process exits.
Severity: process crash of a jsonrpc server built with Go 1.27 or later. The
failure is fatal and not recoverable. One request whose body is decoded as a
`serverRequest` is enough. That is the normal path for a JSON-RPC POST
(`server.go` calls `ReadHeader` for the request body). A body that is not valid
JSON fails earlier in `json.Decoder.Decode` and does not reach this call.
Impact scope:
- Only `protocol/jsonrpc` server request decoding. The only `type Name *T`
declaration in this repository is `type req *serverRequest` in
`protocol/jsonrpc/json.go` (present on `main` at `832124aa` and on `develop` at
`97666ec`).
- Affected builds: Go 1.27 and later, where this `encoding/json` behavior is
the default (reproduced on go1.27.3), and any build with `GOEXPERIMENT=jsonv2`
(reproduced on go1.25.0).
- Default Go 1.25.0 and Go 1.26.10 builds are unaffected.
- The triple and dubbo protocols do not use this method.
- `go.mod` says `go 1.25.0`. The README says "Go 1.25 or later." CI installs
that `go.mod` version (`.github/actions/setup-go` uses `go-version-file:
go.mod`) and does not compile this package with Go 1.27. `go vet` from Go
1.27.3 exits 0 on the unfixed package.
Cause: the method tries to suppress its own `UnmarshalJSON` with a named
pointer type:
```go
type req *serverRequest
if err := json.Unmarshal(raw, req(r)); err != nil {
```
Under `encoding/json` v1 that named pointer type has no `UnmarshalJSON`
method, so the inner call uses the default decoder. Under v2 the decoder still
resolves `(*serverRequest).UnmarshalJSON` and the call recurses. Go 1.27.3 has
no `GODEBUG` setting for this. `GOEXPERIMENT=nojsonv2` selects the old decoder.
Upstream, https://github.com/golang/go/issues/75361 is open. On 2026-01-23
the Go team decided to keep the v2 behavior. The recommended pattern is a named
value type, then a pointer conversion:
```go
type FooNoMethods Foo
return json.Unmarshal(b, (*FooNoMethods)(p))
```
https://go.dev/cl/818760 (`encoding/json/v2: avoid calling methods on named
pointers`) is still status NEW (uploaded 2026-08-20, not merged). The same
local 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).
### How can we reproduce it?
On current `develop` or `main`:
```
export GOTOOLCHAIN=local
go test -count=1 -timeout 3m -run TestServerCodecRead ./protocol/jsonrpc/
```
With Go 1.27.3 this aborts in `TestServerCodecRead` with `fatal error: stack
overflow`. In one local `go test ./...` on unmodified `develop` (`97666ec`),
`protocol/jsonrpc` failed at 4.245s inside `(*serverRequest).UnmarshalJSON`
(`json.go:221`) called from `ReadHeader` (`json.go:309`) and
`TestServerCodecRead` (`json_test.go:84`). The stack limit line was `goroutine
stack exceeds 1000000000-byte limit`.
With Go 1.25.0, or with Go 1.27.3 and `GOEXPERIMENT=nojsonv2`, the same
package tests pass. With Go 1.25.0 and `GOEXPERIMENT=jsonv2`, the same overflow
occurs.
A direct call on the unfixed method, `json.Unmarshal` into a
`*serverRequest` (`TestServerRequestUnmarshalJSON` on this branch before the
fix):
| Toolchain | Result |
| --- | --- |
| go1.25.0 | `ok` (0.754s) |
| go1.25.0 `GOEXPERIMENT=jsonv2` | `fatal error: stack overflow` (1.511s) |
| go1.27.3 | `fatal error: stack overflow` (1.366s) |
The same alias, outside the module, with a counter that returns after 50
re-entries instead of overflowing:
| Toolchain | `type req *T` | `type req T` and `(*req)(p)` |
| --- | --- | --- |
| go1.25.0 | one call, success | one call, success |
| go1.26.10 | one call, success | one call, success |
| go1.27.3 | re-entered 51 times | one call, success |
| go1.27.3 `GOEXPERIMENT=nojsonv2` | one call, success | one call, success |
| go1.25.0 `GOEXPERIMENT=jsonv2` | re-entered 51 times | one call, success |
### Environment
- Repository: apache/dubbo-go. `main`
`832124aaacf0283445d379e935ff5d73695fa84d`. `develop`
`97666ec89ab0c4a0fe949778f0f9a52d3b9b4f1b`. Both contain `type req
*serverRequest` in `protocol/jsonrpc/json.go`.
- Module directive: `go 1.25.0`. README requirement: Go 1.25 or later.
- Go: go1.25.0, go1.26.10, and go1.27.3, `GOTOOLCHAIN=local`, darwin/arm64.
The overflow is in `encoding/json`, in code that is not OS-specific. These runs
were on darwin/arm64 only.
- OS: macOS, darwin/arm64.
--
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]