Skip to content

Commit

Permalink
Merge pull request #89 from anthonyraymond/patch-1
Browse files Browse the repository at this point in the history
Increase readTimeout tolerance according to RFC
  • Loading branch information
worg authored Jan 7, 2021
2 parents ca15f4f + 23a46f5 commit 9c81a64
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (c *Conn) readLoop() {
// infinite timeout
c.rw.SetReadDeadline(time.Time{})
} else {
c.rw.SetReadDeadline(time.Now().Add(readTimeout))
c.rw.SetReadDeadline(time.Now().Add(readTimeout * 2))
}
f, err := reader.Read()
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"runtime"
"testing"
"time"

"github.com/go-stomp/stomp"
. "gopkg.in/check.v1"
Expand Down Expand Up @@ -45,6 +46,37 @@ func (s *ServerSuite) TestConnectAndDisconnect(c *C) {
conn.Close()
}


func (s *ServerSuite) TestHeartBeatingTolerance(c *C) {
// Heart beat should not close connection exactly after not receiving message after cx
// it should add a pretty decent amount of time to counter network delay of other timing issues
addr := ":59092"
l, err := net.Listen("tcp", addr)
c.Assert(err, IsNil)
defer func() { l.Close() }()
serv := Server{
Addr: "",
Authenticator: nil,
QueueStorage: nil,
HeartBeat: 5 * time.Millisecond,
}
go serv.Serve(l)

conn, err := net.Dial("tcp", "127.0.0.1"+addr)
c.Assert(err, IsNil)
defer conn.Close()

client, err := stomp.Connect(conn, stomp.ConnOpt.HeartBeat(5 * time.Millisecond, 5 * time.Millisecond))
c.Assert(err, IsNil)
defer client.Disconnect()

time.Sleep(serv.HeartBeat * 50) // let it go for some time to allow client and server to exchange some heart beat

// Ensure the server has not closed his readChannel
err = client.Send("/topic/whatever", "text/plain", []byte("hello"))
c.Assert(err, IsNil)
}

func (s *ServerSuite) TestSendToQueuesAndTopics(c *C) {
ch := make(chan bool, 2)
println("number cpus:", runtime.NumCPU())
Expand Down

0 comments on commit 9c81a64

Please sign in to comment.