Skip to content

Conversation

@adhocore
Copy link
Contributor

@adhocore adhocore commented Nov 22, 2023

GODRIVER-3056
(i created an issue in the jira but it vanished never to be found again - also for a opensource project hosted in github it is a bit of a stretch to login to yet another server just to file an issue)

Summary

[ERROR] interface conversion: interface is nil, not bsoncodec.Value

v1.13.0 (in fact v1.12.2 also) introduces panics and hence a breaking change with the bson codec_cache
below is stack trace from the system that encountered issue - and it is confirmed that v1.12.1 does not have this issue which i re tested by reverting the version back.

Stack trace:
goroutine 292 [running]:
runtime/debug.Stack()
	/usr/local/go/src/runtime/debug/stack.go:24 +0x5e
github.com/adhocore/module/web.errlogc(0xc00090a480, {0xc0004bdb58?, 0x1, 0xc000000b40?})
	~/projects/my/module/web/helper.go:297 +0xcc
github.com/adhocore/module/web.errlog(0xc18500?, {0xc0004bdb58, 0x1, 0x1})
	~/projects/my/module/web/helper.go:282 +0x39
github.com/adhocore/module/web.errorx(0xc000209800, {0x7f77785800b8?, 0xc000300390})
	~/projects/my/module/web/helper.go:175 +0x66e
github.com/adhocore/module/web.bootstrap.func2(0x10?, {0xc17300?, 0xc000300390?})
	~/projects/my/module/web/app.go:150 +0x3e
github.com/adhocore/module/web.bootstrap.New.func3.1()
	~/go/pkg/mod/github.com/gofiber/fiber/[email protected]/middleware/recover/recover.go:31 +0x72
panic({0xc17300?, 0xc000300390?})
	/usr/local/go/src/runtime/panic.go:914 +0x21f
go.mongodb.org/mongo-driver/bson/bsoncodec.(*typeEncoderCache).LoadOrStore(...)
	~/go/pkg/mod/go.mongodb.org/[email protected]/bson/bsoncodec/codec_cache.go:45
go.mongodb.org/mongo-driver/bson/bsoncodec.(*Registry).storeTypeEncoder(0xc00032e2a0?, {0xf48e88?, 0xc17100?}, {0x0, 0x0})
	~/go/pkg/mod/go.mongodb.org/[email protected]/bson/bsoncodec/registry.go:416 +0x77
go.mongodb.org/mongo-driver/bson/bsoncodec.(*Registry).LookupEncoder(0xc00032e2a0, {0xf48e88, 0xc17100})
	~/go/pkg/mod/go.mongodb.org/[email protected]/bson/bsoncodec/registry.go:411 +0x1fa
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).describeStructSlow(0xc0001db4c0, 0xcc0380?, {0xf48e88, 0xcce820}, 0x0, 0x0)
	~/go/pkg/mod/go.mongodb.org/[email protected]/bson/bsoncodec/struct_codec.go:515 +0x225
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).describeStruct(0xc0001db4c0, 0x1c?, {0xf48e88?, 0xcce820}, 0x53?, 0x5c?)
	~/go/pkg/mod/go.mongodb.org/[email protected]/bson/bsoncodec/struct_codec.go:483 +0x9a
go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).DecodeValue(0xc0001db4c0, {0xc00032e2a0, 0x0, {0x0, 0x0}, {0x0, 0x0}, 0x0, 0x0, 0x0, ...}, ...)
	~/go/pkg/mod/go.mongodb.org/[email protected]/bson/bsoncodec/struct_codec.go:282 +0x111
go.mongodb.org/mongo-driver/bson/bsoncodec.(*PointerCodec).DecodeValue(0xc0001db500, {0xc00032e2a0, 0x0, {0x0, 0x0}, {0x0, 0x0}, 0x0, 0x0, 0x0, ...}, ...)
	~/go/pkg/mod/go.mongodb.org/[email protected]/bson/bsoncodec/pointer_codec.go:91 +0x2ab
go.mongodb.org/mongo-driver/bson.(*Decoder).Decode(0xc0006a00f0, {0xbc92a0, 0xc0003e8108})
	~/go/pkg/mod/go.mongodb.org/[email protected]/bson/decoder.go:134 +0x3e3
go.mongodb.org/mongo-driver/mongo.(*Cursor).Decode(0x7f777857e6b0?, {0xbc92a0, 0xc0003e8108})
	~/go/pkg/mod/go.mongodb.org/[email protected]/mongo/cursor.go:275 +0x8e
github.com/adhocore/module/model.(*Scrip).fromCursor(0xc00035e1c0, 0xf40328?)
	~/projects/my/module/model/scrip.go:150 +0x6b
github.com/adhocore/module/model.(*Stocks).loadScrips(0xc000aaac60, 0x0, {0x0, 0x0, 0x0})
	~/projects/my/module/model/stocks.go:234 +0x2a9

for some reason the cache returned nil as value with true as loaded flag but this is buggy.

Background & Motivation

the issue is noticed in LoadOrStore() but not in Load() and i am sure they both need to work similarly. Load() already checks if the value itself is nil or not but LoadOrStore doesn't, this PR fixes that

@adhocore adhocore requested a review from a team as a code owner November 22, 2023 10:10
@adhocore adhocore requested review from matthewdale and removed request for a team November 22, 2023 10:11
@qingyang-hu qingyang-hu changed the title fix panic on type conversion of nil val in bson codec_cache GODRIVER-3051 fix panic on type conversion of nil val in bson codec_cache Nov 22, 2023
@qingyang-hu qingyang-hu changed the title GODRIVER-3051 fix panic on type conversion of nil val in bson codec_cache GODRIVER-3056 fix panic on type conversion of nil val in bson codec_cache Nov 22, 2023
@qingyang-hu qingyang-hu self-requested a review November 22, 2023 14:41
@adhocore
Copy link
Contributor Author

any updates on it please? if there is another PR with more proper fix then we can link up and close it i guess. what is important is we have a release fixing the issue with breaking change. thanks

@qingyang-hu
Copy link
Collaborator

Hello @adhocore, we appreciate your contribution to the MongoDB Go Driver. Currently, the team is reviewing PR #1477, which fixes the root cause of the nil interface panic. The cache mechanism introduced in v1.12.2 and v1.13.0 stores nil encoders/decoders, so the panic happens when they are retrieved at mongo-driver/bson/bsoncodec.(*StructCodec).describeStructSlow. We will close this one if PR #1477 is accepted. You are welcome to comment on the PR #1477, too.

@adhocore
Copy link
Contributor Author

thank you very much. i am all in for fixing the root cause, more so than fixing symptoms. so yea let me close it ;)

@adhocore adhocore closed this Nov 29, 2023
@adhocore adhocore deleted the patch-1 branch November 29, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants