Skip to content

Commit fd798a4

Browse files
committed
Added code to improve timeout on blocked read.
1 parent c1a1e09 commit fd798a4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cmd/agent/app/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (a *Agent) Run(o *options.GrpcProxyAgentOptions, drainCh, stopCh <-chan str
9999
defer a.adminServer.Close()
100100

101101
<-stopCh
102+
102103
klog.V(1).Infoln("Shutting down agent.")
103104

104105
return nil

pkg/agent/client.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,19 @@ func (a *Client) remoteToProxy(connID int64, eConn *endpointConn) {
538538
}
539539

540540
for {
541+
select {
542+
case <-a.stopCh:
543+
return
544+
default:
545+
}
546+
timeout := time.Now().Add(15 * time.Second)
547+
eConn.conn.SetReadDeadline(timeout)
541548
n, err := eConn.conn.Read(buf[:])
542549
klog.V(5).InfoS("received data from remote", "bytes", n, "connectionID", connID)
543550

544-
if err == io.EOF {
551+
if err == os.ErrDeadlineExceeded {
552+
continue
553+
} else if err == io.EOF {
545554
klog.V(2).InfoS("remote connection EOF", "connectionID", connID)
546555
return
547556
} else if err != nil {

0 commit comments

Comments
 (0)