Skip to content

Commit cc41c01

Browse files
lgarofaloLeland Garofalo
and
Leland Garofalo
authored
Adjust reporting of connection failure metric (#389)
Co-authored-by: Leland Garofalo <[email protected]>
1 parent 6068e4c commit cc41c01

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

server/server.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,23 @@ type handler struct {
166166
closed bool
167167
}
168168

169-
func (h *handler) close() {
169+
func (h *handler) close(err error) {
170170
if !h.closed {
171171
h.conn.Close() // ignoring error: what can we do?
172172
h.s.mtx.Lock()
173173
delete(h.s.listeners[h.listener], h.conn)
174174
h.s.mtx.Unlock()
175-
logConnFailure()
176175
h.closed = true
176+
if err != nil {
177+
logConnFailure()
178+
}
177179
}
178180
}
179181

180182
func (h *handler) closeWithWritingErr(err error) {
181183
if !h.closed {
182184
log.Errorf("connection %v: error in writing response %v", h.name, err)
183-
h.close()
185+
h.close(err)
184186
}
185187
}
186188

@@ -251,7 +253,7 @@ func (h *handler) loop() error {
251253
}
252254
h.mtx.Lock()
253255
defer h.mtx.Unlock()
254-
h.close()
256+
h.close(err)
255257
return err
256258
}
257259
// In the event of a read timeout, gracefully close
@@ -260,7 +262,8 @@ func (h *handler) loop() error {
260262
h.tokens.Acquire(ctx, int64(h.s.config.maxConnPendingRequests))
261263
h.mtx.Lock()
262264
defer h.mtx.Unlock()
263-
h.close()
265+
// Don't pass err here since this was a graceful close
266+
h.close(nil)
264267
return err
265268
}
266269

0 commit comments

Comments
 (0)