Skip to content

Conversation

mariuso
Copy link

@mariuso mariuso commented Jul 6, 2025

Health checks connect and immediately disconnect without sending any data, this creates noisy logs.

This PR fixes it by only logging errors for connections that actually tried to send SMTP commands. Health checks that send nothing are now silent.

What changed:

  • Track whether a connection sent any data
  • Skip error logging for zero-byte connections
  • Real SMTP errors still get logged normally

Includes a test that proves health checks no longer spam the logs.

Addresses issue emersion#236 where health checks and load balancer probes
that connect and immediately disconnect generate unnecessary
'connection reset by peer' error logs.

Changes:
- Add hasReceivedData field to Conn struct to track data reception
- Set flag in readLine() when SMTP data is successfully read
- Only log connection errors if data was actually received
- Add comprehensive test covering both scenarios

This eliminates log spam from health checks while preserving error
visibility for legitimate SMTP sessions.

Fixes: emersion#236
@emersion
Copy link
Owner

emersion commented Jul 6, 2025

Sending nothing should not cause a connection error, it should cause an immediate io.EOF.

When clients connect and immediately disconnect without sending data
(common for health checks), return io.EOF instead of connection reset
error. This prevents noisy error logs for normal health check behavior.

- Modified readLine() to detect zero-byte connections and return EOF
- Removed hasReceivedData check from error logging
- Added tests to verify health checks don't generate error logs
- Real connection errors are still properly logged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants