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 1 commit
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 @@ -162,13 +162,18 @@ 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 tcpTimeout *time.Duration
tcpTimeoutMinVal := time.Second * 1
ChangedenCZD marked this conversation as resolved.
Show resolved Hide resolved
if tcpTimeout, err = parseTimeDurationByRange(c.TcpReadTimeout, &tcpTimeoutMinVal, nil); err != nil {
return perrors.WithMessagef(err, "time.ParseDuration(TcpReadTimeout{%#v})", c.TcpReadTimeout)
}
c.tcpReadTimeout = *tcpTimeout

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

if c.waitTimeout, err = time.ParseDuration(c.WaitTimeout); err != nil {
return perrors.WithMessagef(err, "time.ParseDuration(WaitTimeout{%#v})", c.WaitTimeout)
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) {
result, err := time.ParseDuration(timeStr)
if err != nil {
return nil, err
}
if min != nil && max != nil && *min > *max {
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