Azure / go-ntlmssp

NTLM/Negotiate authentication over HTTP
MIT License
189 stars 67 forks source link

Error 401 with concurrent requests #43

Open jon4hz opened 1 year ago

jon4hz commented 1 year ago

When I tried to use this library with concurrent api calls, I sometimes get an error 401.

url, user, password := "http://www.example.com/secrets", "robpike", "pw123"
client := &http.Client{
  Transport: ntlmssp.Negotiator{
    RoundTripper:&http.Transport{},
  },
}
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
  wg.Add(1)
  go func() {
    defer wg.Done()
    req, _ := http.NewRequest("GET", url, nil)
    req.SetBasicAuth(user, password)
    res, _ := client.Do(req)
    fmt.Println(resp.StatusCode)
  }()
}
wg.Wait()

If I make sure that the client only uses 1 active connection, I don't get any error. So I'm guessing this is a bug, right?

client := &http.Client{
  Transport: ntlmssp.Negotiator{
    RoundTripper:&http.Transport{
      MaxConnsPerHost: 1,  // limit connections
    },
  },
}