Skip to content

Commit

Permalink
Merge pull request kata-containers#397 from lifupan/fix_stdouthang
Browse files Browse the repository at this point in the history
agent: Fix the issue of stdout hang on builtin proxy
  • Loading branch information
Julio Montes authored Oct 16, 2018
2 parents 1aeaf24 + 3a678a9 commit 03f040f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions protocols/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ func parse(sock string) (string, *url.URL, error) {
return grpcAddr, addr, nil
}

// This function is meant to run in a go routine since it will send ping
// commands every second. It behaves as a heartbeat to maintain a proper
// communication state with the Yamux server in the agent.
func heartBeat(session *yamux.Session) {
if session == nil {
return
}

for {
if session.IsClosed() {
break
}

session.Ping()

// 1 Hz heartbeat
time.Sleep(time.Second)
}
}

func agentDialer(addr *url.URL, enableYamux bool) dialer {
var d dialer
switch addr.Scheme {
Expand Down Expand Up @@ -196,11 +216,15 @@ func agentDialer(addr *url.URL, enableYamux bool) dialer {
sessionConfig := yamux.DefaultConfig()
// Disable keepAlive since we don't know how much time a container can be paused
sessionConfig.EnableKeepAlive = false
sessionConfig.ConnectionWriteTimeout = time.Second
session, err = yamux.Client(conn, sessionConfig)
if err != nil {
return nil, err
}

// Start the heartbeat in a separate go routine
go heartBeat(session)

var stream net.Conn
stream, err = session.Open()
if err != nil {
Expand Down

0 comments on commit 03f040f

Please sign in to comment.