MCPcopy
hub / github.com/grafana/dskit / Close

Method Close

middleware/zero_response.go:104–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

102var authRegexp = regexp.MustCompile(`((?i)\r\nauthorization:\s+)(\S+\s+)(\S+)`)
103
104func (zc *zeroResponseConn) Close() error {
105 err := zc.Conn.Close()
106
107 zc.once.Do(func() {
108 zc.bufHolderMux.Lock()
109 defer zc.bufHolderMux.Unlock()
110
111 // If buffer was already returned, it means there was some data written on the connection, nothing to do.
112 if zc.bufHolder == nil {
113 return
114 }
115
116 // If we didn't write anything to this connection, and we've got timeout while reading data, it looks like
117 // slow a slow client failing to send a request to us.
118 if !zc.lastReadErrIsDeadlineExceeded.Load() {
119 return
120 }
121
122 b := zc.bufHolder.buf
123 b = authRegexp.ReplaceAll(b, []byte("${1}${2}***")) // Replace value in Authorization header with ***.
124
125 _ = zc.log.Log("msg", "read timeout, connection closed with no response", "read", strconv.Quote(string(b)), "remote", zc.RemoteAddr().String())
126
127 zc.returnPool.Put(zc.bufHolder)
128 zc.bufHolder = nil
129 })
130
131 return err
132}

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.65
StringMethod · 0.65
PutMethod · 0.65
DoMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected