Skip to content

Commit

Permalink
Merge pull request #352 from AlphaB/req_timeout_348
Browse files Browse the repository at this point in the history
nsqd: Make REQ timeout limit configurable Fixes #348
  • Loading branch information
mreiferson committed May 23, 2014
2 parents 0457c28 + a32af8d commit c2ecf22
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
msgTimeout = flagSet.String("msg-timeout", "60s", "duration to wait before auto-requeing a message")
maxMsgTimeout = flagSet.Duration("max-msg-timeout", 15*time.Minute, "maximum duration before a message will timeout")
maxMsgSize = flagSet.Int64("max-msg-size", 1024768, "maximum size of a single message in bytes")
maxReqTimeout = flagSet.Duration("max-req-timeout", 1*time.Hour, "maximum requeuing timeout for a message")
// remove, deprecated
maxMessageSize = flagSet.Int64("max-message-size", 1024768, "(deprecated use --max-msg-size) maximum size of a single message in bytes")
maxBodySize = flagSet.Int64("max-body-size", 5*1024768, "maximum size of a single command body")
Expand Down
3 changes: 3 additions & 0 deletions contrib/nsqd.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ max_msg_timeout = "15m"
## maximum size of a single message in bytes
max_msg_size = 1024768

## maximum requeuing timeout for a message
max_req_timeout = "1h"

## maximum size of a single command body
max_body_size = 5123840

Expand Down
2 changes: 2 additions & 0 deletions nsqd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type nsqdOptions struct {
MaxMsgTimeout time.Duration `flag:"max-msg-timeout"`
MaxMsgSize int64 `flag:"max-msg-size" deprecated:"max-message-size" cfg:"max_msg_size"`
MaxBodySize int64 `flag:"max-body-size"`
MaxReqTimeout time.Duration `flag:"max-req-timeout"`
ClientTimeout time.Duration

// client overridable configuration options
Expand Down Expand Up @@ -83,6 +84,7 @@ func NewNSQDOptions() *nsqdOptions {
MaxMsgTimeout: 15 * time.Minute,
MaxMsgSize: 1024768,
MaxBodySize: 5 * 1024768,
MaxReqTimeout: 1 * time.Hour,
ClientTimeout: 60 * time.Second,

MaxHeartbeatInterval: 60 * time.Second,
Expand Down
6 changes: 2 additions & 4 deletions nsqd/protocol_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/bitly/nsq/util"
)

const maxTimeout = time.Hour

var separatorBytes = []byte(" ")
var heartbeatBytes = []byte("_heartbeat_")
var okBytes = []byte("OK")
Expand Down Expand Up @@ -557,9 +555,9 @@ func (p *protocolV2) REQ(client *clientV2, params [][]byte) ([]byte, error) {
}
timeoutDuration := time.Duration(timeoutMs) * time.Millisecond

if timeoutDuration < 0 || timeoutDuration > maxTimeout {
if timeoutDuration < 0 || timeoutDuration > p.context.nsqd.options.MaxReqTimeout {
return nil, util.NewFatalClientErr(nil, "E_INVALID",
fmt.Sprintf("REQ timeout %d out of range 0-%d", timeoutDuration, maxTimeout))
fmt.Sprintf("REQ timeout %d out of range 0-%d", timeoutDuration, p.context.nsqd.options.MaxReqTimeout))
}

err = client.Channel.RequeueMessage(client.ID, id, timeoutDuration)
Expand Down

0 comments on commit c2ecf22

Please sign in to comment.