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

Fix: fix the exception when tcp timeout is less than 1s for 3.0 #1362 #1380

Merged
Changes from 3 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
26 changes: 24 additions & 2 deletions remoting/getty/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
"dubbo.apache.org/dubbo-go/v3/config"
)

const (
TCP_READ_WRITE_TIMEOUT_MIN_VALUE = time.Second * 1
)

type (
// GettySessionParam is session configuration for getty
GettySessionParam struct {
Expand Down Expand Up @@ -162,11 +166,12 @@ func (c *GettySessionParam) CheckValidity() error {
return perrors.WithMessagef(err, "time.ParseDuration(KeepAlivePeriod{%#v})", c.KeepAlivePeriod)
}

if c.tcpReadTimeout, err = time.ParseDuration(c.TcpReadTimeout); err != nil {
var tcpTimeoutMinVal = TCP_READ_WRITE_TIMEOUT_MIN_VALUE
if c.tcpReadTimeout, err = parseTimeDurationByRange(c.TcpReadTimeout, &tcpTimeoutMinVal, nil); err != nil {
return perrors.WithMessagef(err, "time.ParseDuration(TcpReadTimeout{%#v})", c.TcpReadTimeout)
}

if c.tcpWriteTimeout, err = time.ParseDuration(c.TcpWriteTimeout); err != nil {
if c.tcpWriteTimeout, err = parseTimeDurationByRange(c.TcpWriteTimeout, &tcpTimeoutMinVal, nil); err != nil {
return perrors.WithMessagef(err, "time.ParseDuration(TcpWriteTimeout{%#v})", c.TcpWriteTimeout)
}

Expand All @@ -177,6 +182,23 @@ func (c *GettySessionParam) CheckValidity() error {
return nil
}

func parseTimeDurationByRange(timeStr string, min *time.Duration, max *time.Duration) (time.Duration, error) {
ChangedenCZD marked this conversation as resolved.
Show resolved Hide resolved
result, err := time.ParseDuration(timeStr)
if err != nil {
return *min, err
}
if min != nil && max != nil && *min > *max { // swap
ChangedenCZD marked this conversation as resolved.
Show resolved Hide resolved
min, max = max, min
}
if min != nil && result < *min {
result = *min
}
if max != nil && result > *max {
result = *max
}
return result, nil
}

// CheckValidity confirm client params.
func (c *ClientConfig) CheckValidity() error {
var err error
Expand Down