Skip to content

Commit f9a51e0

Browse files
committed
api: meaningful read/write networt error
We need to add meaningful error descriptions for a read/write socket errors. Part of #129
1 parent dbfaab5 commit f9a51e0

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1414
- Enumeration types for RLimitAction/iterators (#158)
1515
- IsNullable flag for Field (#302)
1616
- More linters on CI (#310)
17+
- Meaningful description for read/write socket errors (#129)
1718

1819
### Changed
1920

connection.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,10 @@ func (conn *Connection) writer(w writeFlusher, c Conn) {
789789
runtime.Gosched()
790790
if len(conn.dirtyShard) == 0 {
791791
if err := w.Flush(); err != nil {
792+
err = ClientError{
793+
ErrIoError,
794+
fmt.Sprintf("failed to flush data to the connection: %s", err),
795+
}
792796
conn.reconnect(err, c)
793797
return
794798
}
@@ -812,6 +816,10 @@ func (conn *Connection) writer(w writeFlusher, c Conn) {
812816
continue
813817
}
814818
if _, err := w.Write(packet.b); err != nil {
819+
err = ClientError{
820+
ErrIoError,
821+
fmt.Sprintf("failed to write data to the connection: %s", err),
822+
}
815823
conn.reconnect(err, c)
816824
return
817825
}
@@ -868,12 +876,20 @@ func (conn *Connection) reader(r io.Reader, c Conn) {
868876
for atomic.LoadUint32(&conn.state) != connClosed {
869877
respBytes, err := read(r, conn.lenbuf[:])
870878
if err != nil {
879+
err = ClientError{
880+
ErrIoError,
881+
fmt.Sprintf("failed to read data from the connection: %s", err),
882+
}
871883
conn.reconnect(err, c)
872884
return
873885
}
874886
resp := &Response{buf: smallBuf{b: respBytes}}
875887
err = resp.decodeHeader(conn.dec)
876888
if err != nil {
889+
err = ClientError{
890+
ErrProtocolError,
891+
fmt.Sprintf("failed to decode IPROTO header: %s", err),
892+
}
877893
conn.reconnect(err, c)
878894
return
879895
}
@@ -883,6 +899,10 @@ func (conn *Connection) reader(r io.Reader, c Conn) {
883899
if event, err := readWatchEvent(&resp.buf); err == nil {
884900
events <- event
885901
} else {
902+
err = ClientError{
903+
ErrProtocolError,
904+
fmt.Sprintf("failed to decode IPROTO_EVENT: %s", err),
905+
}
886906
conn.opts.Logger.Report(LogWatchEventReadFailed, conn, err)
887907
}
888908
continue

errors.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (clierr ClientError) Error() string {
4545
// - request is aborted due to rate limit
4646
func (clierr ClientError) Temporary() bool {
4747
switch clierr.Code {
48-
case ErrConnectionNotReady, ErrTimeouted, ErrRateLimited:
48+
case ErrConnectionNotReady, ErrTimeouted, ErrRateLimited, ErrIoError:
4949
return true
5050
default:
5151
return false
@@ -60,4 +60,5 @@ const (
6060
ErrTimeouted = 0x4000 + iota
6161
ErrRateLimited = 0x4000 + iota
6262
ErrConnectionShutdown = 0x4000 + iota
63+
ErrIoError = 0x4000 + iota
6364
)

0 commit comments

Comments
 (0)