fix possible nil dereference
I've been seeing a stack track panic in these lines. Trying
to be explicit about everything I can see being busted,
to try to narrow it down. It reproduces with dying network
connections, but not yet reliably enough that I have steps.
diff --git a/skabandclient/skabandclient.go b/skabandclient/skabandclient.go
index 1f1e92b..39f6a45 100644
--- a/skabandclient/skabandclient.go
+++ b/skabandclient/skabandclient.go
@@ -101,6 +101,9 @@
if err != nil {
return fmt.Errorf("skabandclient: %w", err)
}
+ if conn == nil {
+ return fmt.Errorf("skabandclient: nil connection")
+ }
defer conn.Close()
// "Upgrade" our connection, like a WebSocket does.
@@ -119,8 +122,12 @@
reader := bufio.NewReader(conn)
resp, err := http.ReadResponse(reader, req)
if err != nil {
- b, _ := io.ReadAll(resp.Body)
- return fmt.Errorf("skabandclient.Dial: read upgrade response: %w: %s", err, b)
+ if resp != nil {
+ b, _ := io.ReadAll(resp.Body)
+ return fmt.Errorf("skabandclient.Dial: read upgrade response: %w: %s", err, b)
+ } else {
+ return fmt.Errorf("skabandclient.Dial: read upgrade response: %w", err)
+ }
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusSwitchingProtocols {