Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set connection deadlines #324

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cli/benchserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"context"
"errors"
"fmt"
"net"
"net/http"
"net/url"
"os"
"strconv"
Expand Down Expand Up @@ -321,6 +323,7 @@ func (c *connections) roundTrip(i int, req serverRequest) (*clientReply, error)
for {
req.ClientIdx = i
conn := c.ws[i]
conn.SetWriteDeadline(time.Now().Add(2 * time.Second))
err := conn.WriteJSON(req)
if err != nil {
c.errLn(err)
Expand All @@ -329,6 +332,8 @@ func (c *connections) roundTrip(i int, req serverRequest) (*clientReply, error)
}
return nil, err
}
// Replies can be bigger, use longer deadline.
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
var resp clientReply
err = conn.ReadJSON(&resp)
if err != nil {
Expand All @@ -345,6 +350,13 @@ func (c *connections) roundTrip(i int, req serverRequest) (*clientReply, error)
// connect to a client.
func (c *connections) connect(i int) error {
tries := 0
dialer := &websocket.Dialer{
NetDial: func(network, addr string) (net.Conn, error) {
return net.DialTimeout(network, addr, time.Second)
},
Proxy: http.ProxyFromEnvironment,
HandshakeTimeout: 2 * time.Second,
}
for {
err := func() error {
host := c.hosts[i]
Expand All @@ -354,7 +366,7 @@ func (c *connections) connect(i int) error {
u := url.URL{Scheme: "ws", Host: host, Path: "/ws"}
c.info("Connecting to ", u.String())
var err error
c.ws[i], _, err = websocket.DefaultDialer.Dial(u.String(), nil)
c.ws[i], _, err = dialer.Dial(u.String(), nil)
if err != nil {
return err
}
Expand Down
Loading