Details
Description
When concurrently encoding structs with an exported "error" field, the following panic may occur:
panic: interface conversion: interface is nil, not bsoncodec.ValueEncoder
|
|
|
goroutine 35 [running]:
|
go.mongodb.org/mongo-driver/bson/bsoncodec.(*typeEncoderCache).LoadOrStore(...)
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/codec_cache.go:45
|
go.mongodb.org/mongo-driver/bson/bsoncodec.(*Registry).storeTypeEncoder(0x14000144c40?, {0x1043ae578?, 0x1043919c0?}, {0x0?, 0x0?})
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/registry.go:416 +0x7c
|
go.mongodb.org/mongo-driver/bson/bsoncodec.(*Registry).LookupEncoder(0x14000144c40, {0x1043ae578, 0x1043919c0})
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/registry.go:411 +0x1f4
|
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).describeStructSlow(0x14000132100, 0x1043a67c0?, {0x1043ae578, 0x104392640}, 0x0, 0x0)
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/struct_codec.go:515 +0x1fc
|
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).describeStruct(0x14000132100, 0x1?, {0x1043ae578?, 0x104392640}, 0xd8?, 0x2b?)
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/struct_codec.go:483 +0xa0
|
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).EncodeValue(0x14000132100, {0x14000144c40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, ...)
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/struct_codec.go:145 +0xc8
|
go.mongodb.org/mongo-driver/bson.(*Encoder).Encode(0x140000a6030, {0x104392640?, 0x1400008e020})
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/encoder.go:119 +0x264
|
go.mongodb.org/mongo-driver/bson.MarshalAppendWithContext({0x14000144c40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, {0x1044a76a0, ...}, ...)
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/marshal.go:208 +0x1f4
|
go.mongodb.org/mongo-driver/bson.MarshalAppendWithRegistry(...)
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/marshal.go:142
|
go.mongodb.org/mongo-driver/bson.MarshalWithRegistry(0x14000144c40, {0x104392640, 0x1400008e020})
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/marshal.go:96 +0x84
|
go.mongodb.org/mongo-driver/bson.Marshal(...)
|
/Users/preston.vasquez/Developer/mongo-go-driver/bson/marshal.go:52
|
main.main.func1()
|
/Users/preston.vasquez/Developer/technical/workshop/mongo/bson/weirerrorthing/main.go:15 +0x80
|
created by main.main
|
/Users/preston.vasquez/Developer/technical/workshop/mongo/bson/weirerrorthing/main.go:13 +0x3c
|
exit status 2
|
Detailed steps to reproduce the problem?
package main
|
|
|
import (
|
"sync"
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
)
|
|
|
func main() {
|
wg := sync.WaitGroup{}
|
wg.Add(10_000)
|
for i := 0; i < 10_000; i++ {
|
go func() {
|
defer wg.Done()
|
bson.Marshal(struct{ LastError error }{})
|
}()
|
}
|
wg.Wait()
|
}
|
Definition of done: what must be done to consider the task complete?
Fix encoding issue, no more panics
The exact Go version used, with patch level:
go version go1.20.5
The exact version of the Go driver used:
v1 development branch
The operating system and version (e.g. Windows 7, OSX 10.8, ...)
darwin/arm64
Security Vulnerabilities
NA
Attachments
Issue Links
- backports
-
GODRIVER-3051 Panic when decoding is done concurrently
-
- Closed
-
- is depended on by
-
GODRIVER-2943 Fix failing logging tests
-
- Closed
-
- is duplicated by
-
GODRIVER-3051 Panic when decoding is done concurrently
-
- Closed
-
- is related to
-
GODRIVER-3051 Panic when decoding is done concurrently
-
- Closed
-