Skip to content

Commit

Permalink
Adjust reporting of connection failure metric (#389)
Browse files Browse the repository at this point in the history
Co-authored-by: Leland Garofalo <[email protected]>
  • Loading branch information
lgarofalo and Leland Garofalo authored Aug 31, 2023
1 parent 6068e4c commit cc41c01
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,23 @@ type handler struct {
closed bool
}

func (h *handler) close() {
func (h *handler) close(err error) {
if !h.closed {
h.conn.Close() // ignoring error: what can we do?
h.s.mtx.Lock()
delete(h.s.listeners[h.listener], h.conn)
h.s.mtx.Unlock()
logConnFailure()
h.closed = true
if err != nil {
logConnFailure()
}
}
}

func (h *handler) closeWithWritingErr(err error) {
if !h.closed {
log.Errorf("connection %v: error in writing response %v", h.name, err)
h.close()
h.close(err)
}
}

Expand Down Expand Up @@ -251,7 +253,7 @@ func (h *handler) loop() error {
}
h.mtx.Lock()
defer h.mtx.Unlock()
h.close()
h.close(err)
return err
}
// In the event of a read timeout, gracefully close
Expand All @@ -260,7 +262,8 @@ func (h *handler) loop() error {
h.tokens.Acquire(ctx, int64(h.s.config.maxConnPendingRequests))
h.mtx.Lock()
defer h.mtx.Unlock()
h.close()
// Don't pass err here since this was a graceful close
h.close(nil)
return err
}

Expand Down

0 comments on commit cc41c01

Please sign in to comment.