inlet/bmp: trust the metrics to check if socket is closed

This is pointless to try to make Write() error on loopback. Maybe we
need 16KB, maybe not. Assume that if we say it is closed, then it is.
This commit is contained in:
Vincent Bernat
2023-02-06 22:53:49 +01:00
parent f07e2070b8
commit 85b7d33d76
2 changed files with 3 additions and 4 deletions

View File

@@ -109,10 +109,10 @@ func TestBMP(t *testing.T) {
if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" {
t.Errorf("Metrics (-got, +want):\n%s", diff)
}
for i := 0; i < 100; i++ {
for i := 0; ; i++ {
if _, err := conn.Write([]byte{1}); err != nil {
break
} else if err == nil && i == 99 {
} else if i >= 200 {
t.Fatal("Write() did not error while connection should be closed")
}
time.Sleep(5 * time.Millisecond)

View File

@@ -34,8 +34,7 @@ func (c *Component) serveConnection(conn *net.TCPConn) error {
case <-c.t.Dying():
// No need to clean up
}
conn.CloseWrite()
conn.CloseRead()
conn.Close()
c.metrics.closedConnections.WithLabelValues(exporterStr).Inc()
return nil
})