[GODRIVER-1654] Panic in bsoncore.appendstring Created: 16/Jun/20  Updated: 27/Oct/23  Resolved: 07/Jul/20

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: 1.3.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Gino Jongenelen Assignee: Isabella Siu (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

go version go1.14.2 darwin/amd64
go version go1.14.2 linux/amd64



 Description   

When running the following code:

c.UpdateOne(ctx,
   bson.M{
      "_id": Id.String(),
   },
   bson.M{
      "$set": object,
   },
   options.Update().SetUpsert(true),
);

we are encountering occasional panics:

panic: runtime error: invalid memory address or nil pointer dereferencepanic: runtime error: 
   invalid memory address or nil pointer dereference[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1064ca7]
goroutine 1537702 [running]:
go.mongodb.org/mongo-driver/x/bsonx/bsoncore.appendstring(...) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/x/bsonx/bsoncore/bsoncore.go:809
go.mongodb.org/mongo-driver/x/bsonx/bsoncore.AppendString(...) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/x/bsonx/bsoncore/bsoncore.go:172
go.mongodb.org/mongo-driver/bson/bsonrw.(*valueWriter).WriteString(0xc0222de190, 0x0, 0x18, 0x0, 0x18) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/bsonrw/value_writer.go:447 +0x10e
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StringCodec).EncodeValue(0xc00002655b, 0xc000170d90, 0x0, 0x1b44820, 0xc0222de190, 0x18064c0, 0xc0126a3400, 0x198, 0xc00002655b, 0x18064c0) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/bsoncodec/string_codec.go:43 +0x178
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).EncodeValue(0x20dd100, 0xc000170d90, 0x0, 0x1b44820, 0xc0222de190, 0x189f360, 0xc0126a3400, 0x199, 0x20dd100, 0x189f360) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/bsoncodec/struct_codec.go:150 +0x6f1
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).EncodeValue(0x20dd100, 0xc000170d90, 0x0, 0x1b44820, 0xc0222de190, 0x18fd100, 0xc0126a3400, 0x199, 0x20dd100, 0x18fd100) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/bsoncodec/struct_codec.go:150 +0x6f1
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).EncodeValue(0x20dd100, 0xc000170d90, 0x0, 0x1b44820, 0xc0222de190, 0x18e8320, 0xc0126a3400, 0x199, 0x100fda9, 0xc0061bf390) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/bsoncodec/struct_codec.go:150 +0x6f1
go.mongodb.org/mongo-driver/bson/bsoncodec.(*PointerCodec).EncodeValue(0xc00017eba0, 0xc000170d90, 0x0, 0x1b44820, 0xc0222de190, 0x1901120, 0xc0126a3400, 0x16, 0xc01fb22cb0, 0xc0061bf428) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/bsoncodec/pointer_codec.go:61 +0x323
go.mongodb.org/mongo-driver/bson/bsoncodec.EmptyInterfaceCodec.EncodeValue(0x183a800, 0xc000170d90, 0x0, 0x1b44820, 0xc0222de190, 0x183a8e0, 0xc01fb22cd0, 0x94, 0xc0157c4468, 0xc0169660d0) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/bsoncodec/empty_interface_codec.go:52 +0x1ba
go.mongodb.org/mongo-driver/bson/bsoncodec.(*MapCodec).mapEncodeValue(0xc000026558, 0xc000170d90, 0xc0222de100, 0x1b2b6c0, 0xc0222de190, 0x1861a60, 0xc01f679d40, 0x15, 0x0, 0xc00017ec60, ...) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/bsoncodec/map_codec.go:106 +0x479
go.mongodb.org/mongo-driver/bson/bsoncodec.(*MapCodec).EncodeValue(0xc000026558, 0xc000170d90, 0x1861a00, 0x1b44820, 0xc0222de190, 0x1861a60, 0xc01f679d40, 0x15, 0xc000580600, 0x4) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/bsoncodec/map_codec.go:66 +0x20a
go.mongodb.org/mongo-driver/bson.(*Encoder).Encode(0xc021265160, 0x1861a60, 0xc01f679d40, 0x1b44820, 0xc0222de190) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/encoder.go:79 +0x183
go.mongodb.org/mongo-driver/bson.MarshalAppendWithContext(0xc000170d90, 0x0, 0xc0167eb600, 0x0, 0x100, 0x1861a60, 0xc01f679d40, 0x0, 0x0, 0x0, ...) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/marshal.go:94 +0x1cb
go.mongodb.org/mongo-driver/bson.MarshalAppendWithRegistry(...) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/bson/marshal.go:70
go.mongodb.org/mongo-driver/mongo.transformBsoncoreDocument(0xc000170d90, 0x1861a60, 0xc01f679d40, 0x0, 0x0, 0xdb12300, 0xc0069ee918, 0x100dbe4) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/mongo/mongo.go:212 +0xee
go.mongodb.org/mongo-driver/mongo.transformUpdateValue(0xc000170d90, 0x1861a60, 0xc01f679d40, 0x1, 0x3a, 0xc021afc100, 0x7, 0x40, 0xc01fb22c90, 0x94) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/mongo/mongo.go:401 +0x867
go.mongodb.org/mongo-driver/mongo.(*Collection).updateOrReplace(0xc01571f7a0, 0x1b351c0, 0xc000026080, 0xc0167eb300, 0x33, 0x100, 0x1861a60, 0xc01f679d40, 0x188e435b510ec500, 0x2, ...) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/mongo/collection.go:506 +0x1cd
go.mongodb.org/mongo-driver/mongo.(*Collection).UpdateOne(0xc01571f7a0, 0x1b351c0, 0xc000026080, 0x1861a60, 0xc01f678e40, 0x1861a60, 0xc01f679d40, 0xc0069eeea0, 0x1, 0x1, ...) /Users/my-name/go/pkg/mod/go.mongodb.org/mongo-driver@v1.3.4/mongo/collection.go:619 +0x141

The payload isn't changing.

 



 Comments   
Comment by Isabella Siu (Inactive) [ 01/Jul/20 ]

Hi jongenelengino@gmail.com,

We don't support concurrently modifying values while they are being marshaled. Changing the value while it's being passed through the marshaling functions can lead a data race, or in this case, a segmentation fault.

Comment by Gino Jongenelen [ 01/Jul/20 ]

Hi Isabella,

 

Yes, that is a possibility. But that should not cause a panic in any case, right?

Comment by Isabella Siu (Inactive) [ 01/Jul/20 ]

Hi jongenelengino@gmail.com,

Is it possible that the struct is being edited while it's being marshaled?

Comment by Gino Jongenelen [ 17/Jun/20 ]

Hi Divjot,

Thanks for you feedback. The struct which is occasionally failing is the following:

type SagaFlow struct {
   transition.Transition   // type Transition struct { State string \n StateChangeLogs []StateChangeLog `sql:"-"` }
 
   id           uuid.UUID
   RequestId    uuid.UUID
   eventData    EventData  // type EventData interface{}
   rawEventData []byte
   eventType    EventType  // type EventType string
 
   repoName string
   factory  func() Entity  
   publish  func(event eh.Event) error
   Error    misc.CustomError // type CustomError struct { Message string \n Code int }
}

Typical payload:

&{
   SagaFlow:{
      Transition:{
         State:Finished 
         StateChangeLogs:[]
      } 
      id:[196 139 69 247 47 98 76 11 136 239 58 79 236 12 18 56] 
      RequestId:e98aa190-9e5e-4c07-8b0f-a81ab20b514b 
      eventData:0xc002190580 
      rawEventData:[123 ... omitted ... 125] 
      eventType:SomeEventType 
      repoName: factory:<nil> 
      publish:0x1707ba0 
      Error:{Message: Code:0}
   }
}

Comment by Divjot Arora (Inactive) [ 16/Jun/20 ]

Hi jongenelengino@gmail.com,

Can you provide information about the object variable? Based on the stack trace, it seems to be a pointer to a struct that has a string field inside of it. Is it possible for you to provide the entire struct declaration and some examples of what it contains when it's used in an UpdateOne call?

– Divjot

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