Skip to content

Commit

Permalink
Fix memory leak when a connection would hit the cluster port and go a…
Browse files Browse the repository at this point in the history
…way (#3513)
  • Loading branch information
jefferai authored Nov 1, 2017
1 parent 0caf6e9 commit 83f77d5
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions vault/request_forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ func (c *Core) startForwarding() error {

// Accept the connection
conn, err := tlsLn.Accept()
if conn != nil {
// Always defer although it may be closed ahead of time
defer conn.Close()
}
if err != nil {
if err != nil || conn == nil {
if conn != nil {
conn.Close()
}
continue
}

Expand All @@ -138,9 +137,7 @@ func (c *Core) startForwarding() error {
if c.logger.IsDebug() {
c.logger.Debug("core: error handshaking cluster connection", "error", err)
}
if conn != nil {
conn.Close()
}
conn.Close()
continue
}

Expand All @@ -153,10 +150,14 @@ func (c *Core) startForwarding() error {

c.logger.Trace("core: got request forwarding connection")
c.clusterParamsLock.RLock()
go fws.ServeConn(conn, &http2.ServeConnOpts{
Handler: c.rpcServer,
})
rpcServer := c.rpcServer
c.clusterParamsLock.RUnlock()
go func() {
defer conn.Close()
fws.ServeConn(conn, &http2.ServeConnOpts{
Handler: rpcServer,
})
}()

default:
c.logger.Debug("core: unknown negotiated protocol on cluster port")
Expand Down

0 comments on commit 83f77d5

Please sign in to comment.