Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1962

WithTransaction mongodb error detection doesn't unwrap errors

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.2
    • 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.

            Assignee:
            isabella.siu@mongodb.com Isabella Siu (Inactive)
            Reporter:
            epelc@greatcloak.com Ed Pelc
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: