[GODRIVER-692] SingleResult.Decode to struct panics with nil pointer dereference Created: 13/Dec/18  Updated: 28/Oct/23  Resolved: 13/Dec/18

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: 0.1.0
Fix Version/s: 0.2.0

Type: Bug Priority: Major - P3
Reporter: David Golden Assignee: David Golden
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

In updating the tools/go-driver POC to the new API, I found a panic. Decoding a SingleResult from RunCommand to a struct panics – apparently because the registry is nil. 

Stack trace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11e5038]
 
goroutine 1 [running]:
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson/bsoncodec.(*Registry).LookupDecoder(0x0, 0x1696440, 0x1508ae0, 0x1696440, 0x1508ae0, 0x199, 0xc0001584c0)
        /Users/david/golang/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson/bsoncodec/registry.go:319 +0x48
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson.(*Decoder).Decode(0xc00016e220, 0x14a7b60, 0xc000152270, 0x14f95e0, 0xc00016e220)
        /Users/david/golang/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson/decoder.go:82 +0x16d
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson.unmarshalFromReader(0x0, 0xc000158400, 0x1693cc0, 0xc0001584c0, 0x14a7b60, 0xc000152270, 0x0, 0x0)
        /Users/david/golang/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson/unmarshal.go:92 +0xe4
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson.UnmarshalWithRegistry(0x0, 0xc000244000, 0xcb, 0x180, 0x14a7b60, 0xc000152270, 0x0, 0x0)
        /Users/david/golang/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson/unmarshal.go:45 +0x11f
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/mongo.(*SingleResult).Decode(0xc000158480, 0x14a7b60, 0xc000152270, 0x0, 0x0)
        /Users/david/golang/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/mongo/single_result.go:43 +0x84
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-tools-common/db.(*SessionProvider).GetNodeType(0xc00000cd00, 0x146b604, 0xc00000cd00, 0x1566690, 0xc00000cd00)
        /Users/david/golang/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-tools-common/db/command.go:131 +0x23e
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-tools-common/db.(*SessionProvider).IsMongos(0xc00000cd00, 0xc0001521b0, 0x15584f6, 0x1c)
        /Users/david/golang/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-tools-common/db/command.go:157 +0x2f
main.main()
        /Users/david/golang/src/github.com/mongodb/mongo-tools/mongotop/main/mongotop.go:96 +0x3d0



 Comments   
Comment by Githook User [ 13/Dec/18 ]

Author:

{'username': 'xdg', 'email': 'xdg@xdg.me', 'name': 'David Golden'}

Message: GODRIVER-692 Set registry on RunCommand result

Change-Id: I8e759ff5e54738684014591654f8e76c37042c52
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/6310dd3c4b6b7db65c30139cb2396288e7d6a7e1

Comment by David Golden [ 13/Dec/18 ]

https://review.gerrithub.io/#/c/mongodb/mongo-go-driver/+/437121/

Generated at Thu Feb 08 08:34:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.