Skip to content

Commit bb06721

Browse files
Handle reconnect failure in websocket gracefully (#226)
1 parent 1146cb3 commit bb06721

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

protocol/logger/job_logger.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,25 @@ func (logger *WebsocketLivelogger) Connect() error {
7979
ctx, cancel := context.WithTimeout(context.Background(), websocketDialTimeout)
8080
defer cancel()
8181
//nolint:bodyclose // websocket.Dial doesn't return an HTTP response body to close
82-
logger.ws, _, err = websocket.Dial(ctx, feedStreamURL.String(), &websocket.DialOptions{
82+
ws, _, err := websocket.Dial(ctx, feedStreamURL.String(), &websocket.DialOptions{
8383
HTTPClient: logger.Connection.HTTPClient(),
8484
HTTPHeader: http.Header{
8585
"Authorization": []string{"Bearer " + logger.Connection.Token},
8686
"User-Agent": []string{"github-act-runner/1.0.0"},
8787
},
8888
})
89+
// While reconnecting never assign this to null
90+
if ws != nil {
91+
logger.ws = ws
92+
}
8993
return err
9094
}
9195

9296
func (logger *WebsocketLivelogger) SendLog(lines *protocol.TimelineRecordFeedLinesWrapper) error {
97+
// Do not try to send if something is wrong
98+
if logger.ws == nil {
99+
return fmt.Errorf("missing websocket connection")
100+
}
93101
ctx, cancel := context.WithTimeout(context.Background(), websocketMessageTimeout)
94102
defer cancel()
95103
return wsjson.Write(ctx, logger.ws, lines)

runnersurvey.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux || darwin || windows || openbsd || netbsd || freebsd
2-
// +build linux darwin windows openbsd netbsd freebsd
32

43
package main
54

runnersurveyunsupported.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !linux && !darwin && !windows && !openbsd && !netbsd && !freebsd
2-
// +build !linux,!darwin,!windows,!openbsd,!netbsd,!freebsd
32

43
package main
54

0 commit comments

Comments
 (0)