Skip to content

Commit

Permalink
Fix a bug: websocket connection closes incorrectly
Browse files Browse the repository at this point in the history
Signed-off-by: Sherlock Holo <[email protected]>
  • Loading branch information
Sherlock-Holo committed Feb 26, 2019
1 parent 10b3508 commit 3f35a30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ func New(cfg *client.Config) (*Client, error) {
tlsConfig.RootCAs = certPool
}

netDialer := net.Dialer{}
dialer := websocket.Dialer{
TLSClientConfig: tlsConfig,
NetDialContext: func(_ context.Context, network, addr string) (conn net.Conn, err error) {
ctx := context.Background()
if cfg.Timeout.Duration > 0 {
ctx, _ = context.WithTimeout(context.Background(), cfg.Timeout.Duration)
}
return netDialer.DialContext(ctx, network, addr)
},
}

return &Client{
Expand Down Expand Up @@ -98,12 +106,7 @@ func (c *Client) reconnect() error {
c.manager.Close()
}

ctx := context.Background()
if c.config.Timeout.Duration > 0 {
ctx, _ = context.WithTimeout(context.Background(), c.config.Timeout.Duration)
}

conn, _, err := c.wsDialer.DialContext(ctx, c.wsURL, nil)
conn, _, err := c.wsDialer.Dial(c.wsURL, nil)
if err != nil {
return errors.WithStack(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package cmd

const version = "0.6.4"
const version = "0.6.5"

0 comments on commit 3f35a30

Please sign in to comment.