Skip to content

Commit

Permalink
Run onConnect handler in the background
Browse files Browse the repository at this point in the history
Before if the onConnect handler ran longer than the ping wait duration then the
server would disconnect the client.  Now we run the onConnect handler in the
background to ensure that pings start sending right away.
  • Loading branch information
ibuildthecloud authored and Craig Jellick committed Aug 30, 2019
1 parent 0badea2 commit 213ba20
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ func connectToProxy(rootCtx context.Context, proxyURL string, headers http.Heade
}
defer ws.Close()

result := make(chan error, 2)

ctx, cancel := context.WithCancel(rootCtx)
defer cancel()

if onConnect != nil {
if err := onConnect(ctx); err != nil {
return err
}
go func() {
if err := onConnect(ctx); err != nil {
result <- err
}
}()
}

session := NewClientSession(auth, ws)
defer session.Close()

result := make(chan error, 1)
go func() {
_, err = session.Serve(ctx)
result <- err
Expand Down

0 comments on commit 213ba20

Please sign in to comment.