Use non-default global DefaultTransport for DefaultClient

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor - P4
    • 2.2.3
    • Affects Version/s: None
    • Component/s: None
    • None
    • Go Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Detailed steps to reproduce the problem?

      This occurs when the user changes the global http.DefaultTransport variable:

      package main
      
      import (
      	"context"
      	"net/http"
      
      	_ "github.com/motemen/go-loghttp/global" // Just this line!
      	"go.mongodb.org/mongo-driver/v2/mongo"
      )
      
      type nonDefaultTransport struct{}
      
      var _ http.RoundTripper = &nonDefaultTransport{}
      
      func (*nonDefaultTransport) RoundTrip(*http.Request) (*http.Response, error) { return nil, nil }
      
      func main() {
      	http.DefaultTransport = &nonDefaultTransport{}
      
      	client, err := mongo.Connect(context.Background())
      	if err != nil {
      		panic(err)
      	}
      
      	defer func() { _ = client.Disconnect(context.Background()) }()
      }
      

      Definition of done: what must be done to consider the task complete?

      We should not define a global client, create one as needed.

      The exact Go version used, with patch level:

      go version go1.23.1 darwin/arm64

      The exact version of the Go driver used:

      1.17.1

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      NA

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      Sonoma 14.5

      Security Vulnerabilities

      NA

              Assignee:
              Selena Zhou
              Reporter:
              Preston Vasquez
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: