Skip to content

Commit

Permalink
Merge pull request samuel#48 from macb/add_authenticate_timeouts
Browse files Browse the repository at this point in the history
Add timeouts around IO calls during authenticate
  • Loading branch information
samuel committed Jan 19, 2015
2 parents bb79e7c + 4f64bfc commit fa6674a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 4 additions & 0 deletions zk/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ func (c *Conn) authenticate() error {

binary.BigEndian.PutUint32(buf[:4], uint32(n))

c.conn.SetWriteDeadline(time.Now().Add(c.recvTimeout * 10))
_, err = c.conn.Write(buf[:n+4])
c.conn.SetWriteDeadline(time.Time{})
if err != nil {
return err
}
Expand All @@ -375,7 +377,9 @@ func (c *Conn) authenticate() error {
// connect response

// package length
c.conn.SetReadDeadline(time.Now().Add(c.recvTimeout * 10))
_, err = io.ReadFull(c.conn, buf[:4])
c.conn.SetReadDeadline(time.Time{})
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions zk/zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package zk
import (
"fmt"
"io"
"log"
"net"
"strings"
"testing"
Expand Down Expand Up @@ -491,7 +490,7 @@ func startSlowProxy(t *testing.T, up, down throttle.Rate, upstream string, adj f
defer cn.Close()
upcn, err := net.Dial("tcp", upstream)
if err != nil {
log.Print(err)
t.Log(err)
return
}
// This will leave hanging goroutines util stopCh is closed
Expand Down

0 comments on commit fa6674a

Please sign in to comment.