Browse Source

[tm-bench] increase pong write timeout by overriding the default handler

pull/1943/head
Anton Kaliaev 7 years ago
parent
commit
081bd0805e
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 13 additions and 1 deletions
  1. +13
    -1
      tm-bench/transacter.go

+ 13
- 1
tm-bench/transacter.go View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"math/rand"
"net"
"net/http"
"net/url"
"os"
@ -91,7 +92,7 @@ func (t *transacter) receiveLoop(connIndex int) {
for {
_, _, err := c.ReadMessage()
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseNormalClosure) {
if !websocket.IsCloseError(err, websocket.CloseNormalClosure) {
t.logger.Error("failed to read response", "err", err)
}
return
@ -105,6 +106,17 @@ func (t *transacter) receiveLoop(connIndex int) {
// sendLoop generates transactions at a given rate.
func (t *transacter) sendLoop(connIndex int) {
c := t.conns[connIndex]
c.SetPingHandler(func(message string) error {
err := c.WriteControl(websocket.PongMessage, []byte(message), time.Now().Add(sendTimeout))
if err == websocket.ErrCloseSent {
return nil
} else if e, ok := err.(net.Error); ok && e.Temporary() {
return nil
}
return err
})
logger := t.logger.With("addr", c.RemoteAddr())
var txNumber = 0


Loading…
Cancel
Save