Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #91 from sboeuf/introduce_heartbeat_yamux
Browse files Browse the repository at this point in the history
proxy: Maintain communication state with a heartbeat
  • Loading branch information
Sebastien Boeuf committed Jul 27, 2018
2 parents 7e2a93d + 063d58f commit c416c9f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions proxy.go
Expand Up @@ -47,15 +47,39 @@ var sandboxID string

var proxyLog = logrus.New()

// 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 serve(servConn io.ReadWriteCloser, proto, addr string, results chan error) (net.Listener, error) {
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(servConn, sessionConfig)
if err != nil {
return nil, err
}

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

// serving connection
l, err := net.Listen(proto, addr)
if err != nil {
Expand Down

0 comments on commit c416c9f

Please sign in to comment.