Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: occasional panic while encoding json #25608

Closed
dup2X opened this issue May 28, 2018 · 5 comments
Closed

encoding/json: occasional panic while encoding json #25608

dup2X opened this issue May 28, 2018 · 5 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@dup2X
Copy link

dup2X commented May 28, 2018

Please answer these questions before submitting your issue. Thanks!

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

go1.8

Does this issue reproduce with the latest release?

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

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

What did you see instead?

panic info:
runtime error: invalid memory address or nil pointer dereference
goroutine 293881879 [running]:
xxxxx.glob..func2.1.1(0xf7e7a0, 0xc4209d0000, 0xf7f1e0, 0xc4208888d0)
/home/...../xxx.go:52 +0x15b
panic(0xb23660, 0xfa5c00)
/usr/local/go1.8/src/runtime/panic.go:489 +0x2cf
encoding/json.(*encodeState).marshal.func1(0xc421b15658)
/usr/local/go1.8/src/encoding/json/encode.go:288 +0x159
panic(0xb23660, 0xfa5c00)
/usr/local/go1.8/src/runtime/panic.go:489 +0x2cf
encoding/json.(*encodeState).string(0xc420aa89a0, 0x0, 0xb, 0x1, 0xb)
/usr/local/go1.8/src/encoding/json/encode.go:887 +0x86
encoding/json.stringEncoder(0xc420aa89a0, 0xae7980, 0xc42041dc50, 0x98, 0xc420410100)
/usr/local/go1.8/src/encoding/json/encode.go:608 +0x214
encoding/json.(*mapEncoder).encode(0xc420497260, 0xc420aa89a0, 0xb1e380, 0xc421479a38, 0x195....

@alexd765
Copy link
Contributor

Go 1.8 is quite old. Can you check if it also happens with 1.10?
Can you post the code that triggered this?

@agnivade
Copy link
Contributor

Please fill the complete issue template. Thanks.

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 28, 2018
@ALTree ALTree changed the title Panic happened occasionally json/encode.go encoding/json: occasional panic while encoding json May 28, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone May 31, 2018
@dup2X
Copy link
Author

dup2X commented Jun 1, 2018

runtime error: invalid memory address or nil pointer dereference
.......
panic(0xb24920, 0xfa7c40)
/usr/local/go1.8/src/runtime/panic.go:489 +0x2cf
encoding/json.(*encodeState).marshal.func1(0xc420b39640)
/usr/local/go1.8/src/encoding/json/encode.go:288 +0x159
panic(0xb24920, 0xfa7c40)
/usr/local/go1.8/src/runtime/panic.go:489 +0x2cf
encoding/json.(*encodeState).string(0xc420754000, 0x0, 0x11, 0x1, 0x11)
/usr/local/go1.8/src/encoding/json/encode.go:887 +0x86
encoding/json.stringEncoder(0xc420754000, 0xae8b00, 0xc42053cd60, 0x98, 0xc420530100)
/usr/local/go1.8/src/encoding/json/encode.go:608 +0x214
encoding/json.(*mapEncoder).encode(0xc420404f10, 0xc420754000, 0xb1f640, 0xc421639268, 0x195, 0x100)
/usr/local/go1.8/src/encoding/json/encode.go:690 +0x589
encoding/json.(*mapEncoder).(encoding/json.encode)-fm(0xc420754000, 0xb1f640, 0xc421639268, 0x195, 0x100)
/usr/local/go1.8/src/encoding/json/encode.go:706 +0x64
encoding/json.(*structEncoder).encode(0xc4203f3980, 0xc420754000, 0xb94f60, 0xc421639220, 0x199, 0x100)
/usr/local/go1.8/src/encoding/json/encode.go:645 +0x253
encoding/json.(*structEncoder).(encoding/json.encode)-fm(0xc420754000, 0xb94f60, 0xc421639220, 0x199, 0xc421630100)
/usr/local/go1.8/src/encoding/json/encode.go:659 +0x64
encoding/json.(*ptrEncoder).encode(0xc42052e458, 0xc420754000, 0xbcda20, 0xc4214640a8, 0x196, 0x100)
/usr/local/go1.8/src/encoding/json/encode.go:786 +0xe3
encoding/json.(*ptrEncoder).(encoding/json.encode)-fm(0xc420754000, 0xbcda20, 0xc4214640a8, 0x196, 0xbc0100)
/usr/local/go1.8/src/encoding/json/encode.go:791 +0x64
encoding/json.(*arrayEncoder).encode(0xc42052e460, 0xc420754000, 0xad54c0, 0xc420a86000, 0x97, 0x100)
/usr/local/go1.8/src/encoding/json/encode.go:767 +0xf5
encoding/json.(*arrayEncoder).(encoding/json.encode)-fm(0xc420754000, 0xad54c0, 0xc420a86000, 0x97, 0x100)
/usr/local/go1.8/src/encoding/json/encode.go:774 +0x64
encoding/json.(*sliceEncoder).encode(0xc42052e468, 0xc420754000, 0xad54c0, 0xc420a86000, 0x97, 0xad0100)
/usr/local/go1.8/src/encoding/json/encode.go:741 +0xc1
encoding/json.(*sliceEncoder).(encoding/json.encode)-fm(0xc420754000, 0xad54c0, 0xc420a86000, 0x97, 0xc420a80100)
/usr/local/go1.8/src/encoding/json/encode.go:753 +0x64
encoding/json.(*encodeState).reflectValue(0xc420754000, 0xad54c0, 0xc420a86000, 0x97, 0xc420a80100)
/usr/local/go1.8/src/encoding/json/encode.go:323 +0x82
encoding/json.interfaceEncoder(0xc420754000, 0xb0e400, 0xc420abc258, 0x94, 0x100)
/usr/local/go1.8/src/encoding/json/encode.go:617 +0xdb
encoding/json.(*structEncoder).encode(0xc4203f3800, 0xc420754000, 0xb66ee0, 0xc420abc240, 0x99, 0xb60100)
/usr/local/go1.8/src/encoding/json/encode.go:645 +0x253
encoding/json.(*structEncoder).(encoding/json.encode)-fm(0xc420754000, 0xb66ee0, 0xc420abc240, 0x99, 0xc420ab0100)
/usr/local/go1.8/src/encoding/json/encode.go:659 +0x64
encoding/json.(*encodeState).reflectValue(0xc420754000, 0xb66ee0, 0xc420abc240, 0x99, 0x100)
/usr/local/go1.8/src/encoding/json/encode.go:323 +0x82
encoding/json.(*encodeState).marshal(0xc420754000, 0xb66ee0, 0xc420abc240, 0xb60100, 0x0, 0x0)
/usr/local/go1.8/src/encoding/json/encode.go:296 +0xb8
encoding/json.Marshal(0xb66ee0, 0xc420abc240, 0xb66ee0, 0xc420abc240, 0xc420a86000, 0x1, 0x2)
/usr/local/go1.8/src/encoding/json/encode.go:161 +0x6e


type XXXX struct {
      Code int
      Data interface{}
}

var marshalFn = func(data interface{}, err error) ([]byte, error) {
    ret := XXXX{
        Code:  0,
        Data:   v,
    }
    return json.Marshal(ret) // panic 
}

func handle(ctx context.Context, req *http.Request) (interface{}, error) {
        return StructA{}
}

func main() {
      for {
         data, err := handleRequest(ctx, req)
         marshalFn(data, err)
     }
}

@agnivade
Copy link
Contributor

agnivade commented Jun 1, 2018

Thank you. Unfortunately, we still do not have enough info to debug this. You need to fill the complete issue template and try with 1.10.2 and see if it still crashes with it.

We need a full working program with the steps to reproduce, not just a snippet. In your code, it is not known what is the value of the data variable being passed. Once you get that, you can probably simplify the code to directly do a json.Marshal and cause the panic.

Thanks.

@agnivade agnivade added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Aug 12, 2018
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants