Hi, I am using the OpenAI-go [lib](https://github.com/openai/openai-go/) to 
make calls to various LLM providers. In using the lib, I have stumbled on a 
very very rare use case of a panic in the transport.go. I know that I am 
using a lib that could be faulty, but I verified that I am using ONLY the 
http's package default client to make requests. No middleware, no custom 
client and no rountripper (other than the DefaultTransport being used --- 
which is the default in the net/http library).

```bash
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7cbf8d]

goroutine 102401 [running]:
net/http.(*Transport).roundTrip(0x48c60c0, 0xc00098f180)
/usr/local/go/src/net/http/transport.go:707 +0xbed
net/http.(*Transport).RoundTrip(0xc00007d008?, 0x30ed220?)
/usr/local/go/src/net/http/roundtrip.go:33 +0x18
net/http.send(0xc00098f180, {0x30ed220, 0x48c60c0}, {0xc00abd2b01?, 
0x480773?, 0x0?})
/usr/local/go/src/net/http/client.go:259 +0x5e2
net/http.(*Client).send(0x48fe060, 0xc00098f180, {0xc00d478740?, 0x3a?, 
0x0?})
/usr/local/go/src/net/http/client.go:180 +0x91
net/http.(*Client).do(0x48fe060, 0xc00098f180)
/usr/local/go/src/net/http/client.go:729 +0x9c9
net/http.(*Client).Do(...)
/usr/local/go/src/net/http/client.go:587
github.com/openai/openai-go/v3/internal/requestconfig.(*RequestConfig).Execute(0xc00e21a8f0)
/root/.cache/go-build/github.com/openai/openai-go/[email protected]/internal/requestconfig/requestconfig.go:447
 
+0x845
github.com/openai/openai-go/v3/internal/requestconfig.ExecuteNewRequest({0x311c0b0?,
 
0xc00ba6bda8?}, {0x299dfd5?, 0xc00d4782e0?}, {0x29c1b35?, 0x4804e5?}, 
{0x296d2a0?, 0xc000143408?}, {0x22b6140, 0xc00007b8e0}, ...)
/root/.cache/go-build/github.com/openai/openai-go/[email protected]/internal/requestconfig/requestconfig.go:569
 
+0x9b
github.com/openai/openai-go/v3.(*ChatCompletionService).New(_, {_, _}, 
{{0xc00e93d908, 0x39, 0x4b}, {0xc000b0a020, 0x1a}, {0x0, 0x0, ...}, ...}, 
...)
/root/.cache/go-build/github.com/openai/openai-go/[email protected]/chatcompletion.go:67
 
+0x2be
```

By checking the code at line 707, I see that it does `resp.Request  = 
origReq`. This would mean that `resp` is nil.

I have seen this happen in production in 2 different environments. I am 
also curious to know why the resp is not check to be nil in line 707? This 
assumes that either resp, err = pconn.alt.RoundTrip(req) or resp, err = 
pconn.roundTrip(treq) will ALWAYS return something (if err is not nil). But 
is possible to maybe in a rare race condition that it returns nil, nil? And 
that would make it the it's possible for the resp to be nil. 

Would a safety check there make any sense?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/a71c1f33-cf8f-4302-b8a0-85f65ae54940n%40googlegroups.com.

Reply via email to