-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: API, Error Handling
-
None
-
Fully Compatible
The session `WithTransaction` currently tries to cast the error returned by the user supplied function to see if it is a `CommandError`. I believe it should instead use `errors.As()` to see if the returned error unwraps to a command error so that if a developer wraps an error(ie so you can return a prettier error to users) then the command error will still be detected by the mongodb driver and retry logic still applied.
This block specifically the first line with `err.(CommandError)` should be changed to use `errors.As` instead which will check if the error is a CommandError directly or if it unwraps to one and contains a CommandError.
https://github.com/mongodb/mongo-go-driver/blob/master/mongo/session.go#L196-L200
Example use case: https://play.golang.org/p/pOkZ7a9anzj
https://golang.org/pkg/errors/#As
I believe this is the cause of WriteConflict errors when we moved transactions to production.