registerConnection holds onto conn so it can be closed in the event of a server shutdown. This is useful because hijacked connections or connections dialed to backends don't close when server is shut down. The caller should call the returned delete() function when the connection is done to remove it
(conn io.ReadWriteCloser, gracefulClose func() error)
| 381 | // The caller should call the returned delete() function when the |
| 382 | // connection is done to remove it from memory. |
| 383 | func (h *Handler) registerConnection(conn io.ReadWriteCloser, gracefulClose func() error) (del func()) { |
| 384 | h.connectionsMu.Lock() |
| 385 | h.connections[conn] = openConnection{conn, gracefulClose} |
| 386 | h.connectionsMu.Unlock() |
| 387 | return func() { |
| 388 | h.connectionsMu.Lock() |
| 389 | delete(h.connections, conn) |
| 390 | // if there is no connection left before the connections close timer fires |
| 391 | if len(h.connections) == 0 && h.connectionsCloseTimer != nil { |
| 392 | // we release the timer that holds the reference to Handler |
| 393 | if (*h.connectionsCloseTimer).Stop() { |
| 394 | h.logger.Debug("stopped streaming connections close timer - all connections are already closed") |
| 395 | } |
| 396 | h.connectionsCloseTimer = nil |
| 397 | } |
| 398 | h.connectionsMu.Unlock() |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | // closeConnections immediately closes all hijacked connections (both to client and backend). |
| 403 | func (h *Handler) closeConnections() error { |
no test coverage detected