You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/08/11 11:02:37 UTC

[dubbo-getty] branch master updated: fix(*): revert 17b08d to fix timeout error

This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-getty.git


The following commit(s) were added to refs/heads/master by this push:
     new d711a4b  fix(*): revert 17b08d to fix timeout error
     new 1f33b20  Merge pull request #72 from Mulavar/fix/timeout
d711a4b is described below

commit d711a4ba565e6b36b0171b3a7e19e22a3550254c
Author: dongjianhui03 <do...@meituan.com>
AuthorDate: Wed Aug 11 00:09:19 2021 +0800

    fix(*): revert 17b08d to fix timeout error
---
 connection.go | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/connection.go b/connection.go
index 5c4b43b..fdb638f 100644
--- a/connection.go
+++ b/connection.go
@@ -54,10 +54,10 @@ type gettyConn struct {
 	active        uatomic.Int64  // last active, in milliseconds
 	rTimeout      time.Duration  // network current limiting
 	wTimeout      time.Duration
-	rLastDeadline int64  // lastest network read time
-	wLastDeadline int64  // lastest network write time
-	local         string // local address
-	peer          string // peer address
+	rLastDeadline time.Time // last network read time
+	wLastDeadline time.Time // last network write time
+	local         string    // local address
+	peer          string    // peer address
 	ss            Session
 }
 
@@ -241,12 +241,12 @@ func (t *gettyTCPConn) recv(p []byte) (int, error) {
 		// of the last read deadline exceeded.
 		// See https://github.com/golang/go/issues/15133 for details.
 		currentTime = time.Now()
-		if currentTime.Unix()-t.rLastDeadline > int64(t.rTimeout>>2) {
+		if currentTime.Sub(t.rLastDeadline) > t.rTimeout>>2 {
 			if err = t.conn.SetReadDeadline(currentTime.Add(t.rTimeout)); err != nil {
 				// just a timeout error
 				return 0, perrors.WithStack(err)
 			}
-			t.rLastDeadline = currentTime.Unix()
+			t.rLastDeadline = currentTime
 		}
 	}
 
@@ -271,11 +271,11 @@ func (t *gettyTCPConn) send(pkg interface{}) (int, error) {
 		// of the last write deadline exceeded.
 		// See https://github.com/golang/go/issues/15133 for details.
 		currentTime = time.Now()
-		if currentTime.Unix()-t.wLastDeadline > int64(t.wTimeout>>2) {
+		if currentTime.Sub(t.wLastDeadline) > t.wTimeout>>2 {
 			if err = t.conn.SetWriteDeadline(currentTime.Add(t.wTimeout)); err != nil {
 				return 0, perrors.WithStack(err)
 			}
-			t.wLastDeadline = currentTime.Unix()
+			t.wLastDeadline = currentTime
 		}
 	}
 
@@ -392,11 +392,11 @@ func (u *gettyUDPConn) recv(p []byte) (int, *net.UDPAddr, error) {
 		// of the last read deadline exceeded.
 		// See https://github.com/golang/go/issues/15133 for details.
 		currentTime := time.Now()
-		if currentTime.Unix()-u.rLastDeadline > int64(u.rTimeout>>2) {
+		if currentTime.Sub(u.rLastDeadline) > u.rTimeout>>2 {
 			if err := u.conn.SetReadDeadline(currentTime.Add(u.rTimeout)); err != nil {
 				return 0, nil, perrors.WithStack(err)
 			}
-			u.rLastDeadline = currentTime.Unix()
+			u.rLastDeadline = currentTime
 		}
 	}
 
@@ -439,11 +439,11 @@ func (u *gettyUDPConn) send(udpCtx interface{}) (int, error) {
 		// of the last write deadline exceeded.
 		// See https://github.com/golang/go/issues/15133 for details.
 		currentTime = time.Now()
-		if currentTime.Unix()-u.wLastDeadline > int64(u.wTimeout>>2) {
+		if currentTime.Sub(u.wLastDeadline) > u.wTimeout>>2 {
 			if err = u.conn.SetWriteDeadline(currentTime.Add(u.wTimeout)); err != nil {
 				return 0, perrors.WithStack(err)
 			}
-			u.wLastDeadline = currentTime.Unix()
+			u.wLastDeadline = currentTime
 		}
 	}
 
@@ -564,11 +564,11 @@ func (w *gettyWSConn) updateWriteDeadline() error {
 		// of the last write deadline exceeded.
 		// See https://github.com/golang/go/issues/15133 for details.
 		currentTime = time.Now()
-		if currentTime.Unix()-w.wLastDeadline > int64(w.wTimeout>>2) {
+		if currentTime.Sub(w.wLastDeadline) > w.wTimeout>>2 {
 			if err = w.conn.SetWriteDeadline(currentTime.Add(w.wTimeout)); err != nil {
 				return perrors.WithStack(err)
 			}
-			w.wLastDeadline = currentTime.Unix()
+			w.wLastDeadline = currentTime
 		}
 	}