Skip to content

encoding/json: unexpected fault address 0x26000000c6 #42795

Closed
@nzlov

Description

@nzlov

What version of Go are you using (go version)?

$ go version
go version go1.15.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes, but 1.14.2 is work.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mac/Library/Caches/go-build"
GOENV="/Users/mac/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mac/workspace/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mac/workspace/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/Users/mac/program/go"
GOSUMDB=""
GOTMPDIR=""
GOTOOLDIR="/Users/mac/program/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mac/program/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y7/wj_j6jds1j7bz0bvp_bz1kf00000gn/T/go-build694457940=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

	a := A{}
	m := map[string]interface{}{}
	d, _ := json.Marshal(a)
	json.Unmarshal(d, &m)

Compile docker for linux on macos and run it on k8s

What did you expect to see?

Parse data to map

What did you see instead?

unexpected fault address 0x26000000c6
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0x26000000c6 pc=0x52445d]

goroutine 93 [running]:
runtime.throw(0x1178d74, 0x5)
	/Users/mac/program/go/src/runtime/panic.go:1116 +0x72 fp=0xc00064d768 sp=0xc00064d738 pc=0x437752
runtime.sigpanic()
	/Users/mac/program/go/src/runtime/signal_unix.go:749 +0x405 fp=0xc00064d798 sp=0xc00064d768 pc=0x44dae5
encoding/json.(*encodeState).string(0xc00055e300, 0x26000000c6, 0x102000000c1, 0x2600000001)
	/Users/mac/program/go/src/encoding/json/encode.go:1004 +0x5d fp=0xc00064d7f8 sp=0xc00064d798 pc=0x52445d
encoding/json.stringEncoder(0xc00055e300, 0xfc68c0, 0xc000512d00, 0x98, 0x100)
	/Users/mac/program/go/src/encoding/json/encode.go:645 +0x1d6 fp=0xc00064d878 sp=0xc00064d7f8 pc=0x521896
encoding/json.structEncoder.encode(0xc0006dd800, 0x22, 0x43, 0xc000597590, 0xc00055e300, 0x1166c40, 0xc000512b38, 0x99, 0x100)
	/Users/mac/program/go/src/encoding/json/encode.go:759 +0x2ab fp=0xc00064d910 sp=0xc00064d878 pc=0x52220b
encoding/json.structEncoder.encode-fm(0xc00055e300, 0x1166c40, 0xc000512b38, 0x99, 0x100)
	/Users/mac/program/go/src/encoding/json/encode.go:730 +0x7f fp=0xc00064d968 sp=0xc00064d910 pc=0x52eb9f
encoding/json.structEncoder.encode(0xc0006a8600, 0x3b, 0x43, 0xc00059a150, 0xc00055e300, 0x11733c0, 0xc0005126a0, 0x99, 0x100)
	/Users/mac/program/go/src/encoding/json/encode.go:759 +0x2ab fp=0xc00064da00 sp=0xc00064d968 pc=0x52220b
encoding/json.structEncoder.encode-fm(0xc00055e300, 0x11733c0, 0xc0005126a0, 0x99, 0x100)
	/Users/mac/program/go/src/encoding/json/encode.go:730 +0x7f fp=0xc00064da58 sp=0xc00064da00 pc=0x52eb9f
encoding/json.structEncoder.encode(0xc0006db200, 0x23, 0x43, 0xc00059a1b0, 0xc00055e300, 0x1167360, 0xc0005122c8, 0x99, 0x100)
	/Users/mac/program/go/src/encoding/json/encode.go:759 +0x2ab fp=0xc00064daf0 sp=0xc00064da58 pc=0x52220b
encoding/json.structEncoder.encode-fm(0xc00055e300, 0x1167360, 0xc0005122c8, 0x99, 0x100)
	/Users/mac/program/go/src/encoding/json/encode.go:730 +0x7f fp=0xc00064db48 sp=0xc00064daf0 pc=0x52eb9f
encoding/json.structEncoder.encode(0xc00084a000, 0x20, 0x21, 0xc00059b2c0, 0xc00055e300, 0x11643a0, 0xc000511a60, 0x99, 0x100)
	/Users/mac/program/go/src/encoding/json/encode.go:759 +0x2ab fp=0xc00064dbe0 sp=0xc00064db48 pc=0x52220b
encoding/json.structEncoder.encode-fm(0xc00055e300, 0x11643a0, 0xc000511a60, 0x99, 0x100)
	/Users/mac/program/go/src/encoding/json/encode.go:730 +0x7f fp=0xc00064dc38 sp=0xc00064dbe0 pc=0x52eb9f
encoding/json.structEncoder.encode(0xc0006ce400, 0xd, 0x10, 0xc00059b320, 0xc00055e300, 0x11367c0, 0xc00050e000, 0x99, 0x1130100)
	/Users/mac/program/go/src/encoding/json/encode.go:759 +0x2ab fp=0xc00064dcd0 sp=0xc00064dc38 pc=0x52220b
encoding/json.structEncoder.encode-fm(0xc00055e300, 0x11367c0, 0xc00050e000, 0x99, 0x1c20100)
	/Users/mac/program/go/src/encoding/json/encode.go:730 +0x7f fp=0xc00064dd28 sp=0xc00064dcd0 pc=0x52eb9f
encoding/json.(*encodeState).reflectValue(0xc00055e300, 0x11367c0, 0xc00050e000, 0x99, 0xc000640100)
	/Users/mac/program/go/src/encoding/json/encode.go:358 +0x82 fp=0xc00064dd60 sp=0xc00064dd28 pc=0x51f902
encoding/json.(*encodeState).marshal(0xc00055e300, 0x11367c0, 0xc00050e000, 0xc000640100, 0x0, 0x0)
	/Users/mac/program/go/src/encoding/json/encode.go:330 +0xf4 fp=0xc00064ddc0 sp=0xc00064dd60 pc=0x51f4f4
encoding/json.Marshal(0x11367c0, 0xc00050e000, 0xc000125020, 0x203000, 0x203000, 0x203000, 0x0)
	/Users/mac/program/go/src/encoding/json/encode.go:161 +0x52 fp=0xc00064de38 sp=0xc00064ddc0 pc=0x51e972

Activity

davecheney

davecheney commented on Nov 24, 2020

@davecheney
Contributor

Thank you for raising this issue. Your sample code looks incomplete as the stack trace you included mentioned goroutine 93 whereas the code fragment you provided did not use goroutines.

Can you please

  1. Provide a runnable code sample and steps to reproduce the issue you see.
  2. Please compile and deploy your application with the race detector and confirm that there are no data races present.
added
WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
on Nov 24, 2020
nzlov

nzlov commented on Nov 24, 2020

@nzlov
Author

@davecheney
No data race.
Demo needs to wait.

mvdan

mvdan commented on Nov 24, 2020

@mvdan
Member

Line 1004 in question is if b := s[i]; b < utf8.RuneSelf {, so this is certainly not a bug in json.

Without a reproducer or more details, there's not much we can do here.

xtutu

xtutu commented on Feb 8, 2021

@xtutu

hi, @nzlov I met the same issuse.
Do you solve it?

davecheney

davecheney commented on Feb 8, 2021

@davecheney
Contributor

@xtutu please log a new issue and be sure to complete the entire template. You must provide a way for someone else to reproduce the problem you are seeing.

xtutu

xtutu commented on Feb 8, 2021

@xtutu

@davecheney , i found what happy in my code . it solved.
valueList is data race.

import (
        "encoding/json"
        "fmt"
        "testing"
        "time"
)
func TestABC(t *testing.T) {
        type FF struct {
                EE map[string][]string
        }

        a := make(map[string][]string)
        for i := 0; i < 10000; i++ {
                list := make([]string, 0)
                for j := 0; j < (i % 10) + 1; j++ {
                        list = append(list, "1")
                }
                a[fmt.Sprintf("%d", i)] = list
        }

        // wrong code!
        // this will failed
        for _, valueList := range a {
                go func() {
                        ff := &FF{EE: make(map[string][]string)}
                        ff.EE["x"] = valueList
                        _, _ = json.Marshal(ff)
                }()
        }
        
        // right code!
        // this is ok
        // for _, valueList := range a {
        //       tmpValueList := valueList
        //         go func() {
        //                 ff := &FF{EE: make(map[string][]string)}
        //                 ff.EE["x"] = tmpValueList
        //                 _, _ = json.Marshal(ff)
        //         }()
        // }
        
        time.Sleep(time.Second * 20)
}
davecheney

davecheney commented on Feb 8, 2021

@davecheney
Contributor

Thank you. I am closing and resolving this issue.

removed
WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
on Feb 8, 2021
locked as resolved and limited conversation to collaborators on Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @davecheney@nzlov@mvdan@xtutu

        Issue actions

          encoding/json: unexpected fault address 0x26000000c6 · Issue #42795 · golang/go