Skip to content

Commit

Permalink
Merge pull request #1380 from Chans-Open-Source/feature/fix_the_excep…
Browse files Browse the repository at this point in the history
…tion_when_tcp_timeout_is_less_than_1

Fix: fix the exception when tcp timeout is less than 1s for 3.0 #1362
  • Loading branch information
zouyx authored Aug 24, 2021
2 parents 186dc22 + 6c3e38b commit 3906343
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 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 (
TCPReadWriteTimeoutMinValue = time.Second * 1
)

type (
// GettySessionParam is session configuration for getty
GettySessionParam struct {
Expand Down Expand Up @@ -162,11 +166,11 @@ 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 {
if c.tcpReadTimeout, err = parseTcpTimeoutDuration(c.TcpReadTimeout); 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 = parseTcpTimeoutDuration(c.TcpWriteTimeout); err != nil {
return perrors.WithMessagef(err, "time.ParseDuration(TcpWriteTimeout{%#v})", c.TcpWriteTimeout)
}

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

func parseTcpTimeoutDuration(timeStr string) (time.Duration, error) {
result, err := time.ParseDuration(timeStr)
if err != nil {
return 0, err
}
if result < TCPReadWriteTimeoutMinValue {
return TCPReadWriteTimeoutMinValue, nil
}
return result, nil
}

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

0 comments on commit 3906343

Please sign in to comment.