summaryrefslogtreecommitdiff
path: root/lib/go
diff options
context:
space:
mode:
authorYuxuan 'fishy' Wang <yuxuan.wang@reddit.com>2021-04-27 19:56:58 -0700
committerYuxuan 'fishy' Wang <fishywang@gmail.com>2021-04-28 18:49:58 -0700
commitfe3f8a1279660b2e3a47798fa2c8a7bd6800e4e9 (patch)
tree04a582b268b2ac6d01d128850a42e398dabaff74 /lib/go
parent80415f05d621c861aeaa791fa93a1c3bee8b84bc (diff)
downloadthrift-fe3f8a1279660b2e3a47798fa2c8a7bd6800e4e9.tar.gz
THRIFT-5404: Allow other types of TTransportException to be timeouts
Client: go Currently we only treat TTransportException with typeId == TIMED_OUT as timeout (return true in Timeout function). When opening a new socket, if we got a connect timeout from net.Dial, we wrap the error as TTransportException with typeId == NOT_OPEN, thus it's no longer treated as a timeout error. Change the error to be directly wrapping the original error (instead of recreate a new error with the same error message), and change tTransportException.Timeout to also return true if the wrapped error is a timeout error. This way we don't have to break anything (if code rely on TTransportException.TypeId being NOT_OPEN in this case, that's still true). While I'm here, also update CHANGES.md from #2359.
Diffstat (limited to 'lib/go')
-rw-r--r--lib/go/thrift/socket.go6
-rw-r--r--lib/go/thrift/ssl_socket.go12
-rw-r--r--lib/go/thrift/transport_exception.go2
3 files changed, 16 insertions, 4 deletions
diff --git a/lib/go/thrift/socket.go b/lib/go/thrift/socket.go
index e911bf166..0cf59a0f5 100644
--- a/lib/go/thrift/socket.go
+++ b/lib/go/thrift/socket.go
@@ -166,7 +166,11 @@ func (p *TSocket) Open() error {
p.addr.String(),
p.cfg.GetConnectTimeout(),
)); err != nil {
- return NewTTransportException(NOT_OPEN, err.Error())
+ return &tTransportException{
+ typeId: NOT_OPEN,
+ err: err,
+ msg: err.Error(),
+ }
}
return nil
}
diff --git a/lib/go/thrift/ssl_socket.go b/lib/go/thrift/ssl_socket.go
index 6359a74ce..cd711fffe 100644
--- a/lib/go/thrift/ssl_socket.go
+++ b/lib/go/thrift/ssl_socket.go
@@ -167,7 +167,11 @@ func (p *TSSLSocket) Open() error {
p.hostPort,
p.cfg.GetTLSConfig(),
)); err != nil {
- return NewTTransportException(NOT_OPEN, err.Error())
+ return &tTransportException{
+ typeId: NOT_OPEN,
+ err: err,
+ msg: err.Error(),
+ }
}
} else {
if p.conn.isValid() {
@@ -190,7 +194,11 @@ func (p *TSSLSocket) Open() error {
p.addr.String(),
p.cfg.GetTLSConfig(),
)); err != nil {
- return NewTTransportException(NOT_OPEN, err.Error())
+ return &tTransportException{
+ typeId: NOT_OPEN,
+ err: err,
+ msg: err.Error(),
+ }
}
}
return nil
diff --git a/lib/go/thrift/transport_exception.go b/lib/go/thrift/transport_exception.go
index 0a3f07646..a51510ed9 100644
--- a/lib/go/thrift/transport_exception.go
+++ b/lib/go/thrift/transport_exception.go
@@ -72,7 +72,7 @@ func (p *tTransportException) Unwrap() error {
}
func (p *tTransportException) Timeout() bool {
- return p.typeId == TIMED_OUT
+ return p.typeId == TIMED_OUT || isTimeoutError(p.err)
}
func NewTTransportException(t int, e string) TTransportException {