瀏覽代碼

Fix deadlock in kcp.read

v2ray 9 年之前
父節點
當前提交
a88a120938
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      transport/internet/kcp/connection.go

+ 6 - 2
transport/internet/kcp/connection.go

@@ -179,8 +179,12 @@ func (this *Connection) Read(b []byte) (int, error) {
 			return nBytes, nil
 		}
 		var timer *time.Timer
-		if !this.rd.IsZero() && this.rd.Before(time.Now()) {
-			timer = time.AfterFunc(this.rd.Sub(time.Now()), this.dataInputCond.Signal)
+		if !this.rd.IsZero() {
+			duration := this.rd.Sub(time.Now())
+			if duration <= 0 {
+				return 0, errTimeout
+			}
+			timer = time.AfterFunc(duration, this.dataInputCond.Signal)
 		}
 		this.dataInputCond.L.Lock()
 		this.dataInputCond.Wait()