Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle zero-byte TCP healthcheck connections #236

Open
nimjor opened this issue Oct 4, 2023 · 4 comments
Open

Handle zero-byte TCP healthcheck connections #236

nimjor opened this issue Oct 4, 2023 · 4 comments
Labels

Comments

@nimjor
Copy link

nimjor commented Oct 4, 2023

In an environment like kubernetes hosted on AWS, the server needs to handle health checks from load balancers. A TCP health check only checks that a connection can be established, and then closes without sending any data or waiting for a greeting. go-smtp's Server then logs error messages like

handler error: read tcp 127.0.0.1:9025->127.0.0.1:55372: read: connection reset by peer

which in the case of most health check intervals (< 5 min) means noisy logs with lots of pointless error messages (the noise is the problem, not any functionality of the Server itself). Instead, Server.handleConn() should check whether any bytes were sent and only log an error if the connection was non-empty.

@emersion
Copy link
Owner

emersion commented Oct 4, 2023

A connection close should result in EOF I think, not ECONNRESET…

@nimjor
Copy link
Author

nimjor commented Oct 4, 2023

This is reproducible locally by simply starting the SMTP server listening on localhost:9025, then in a terminal issuing nc -vz localhost 9025:

❯ nc -vz localhost 9025
Connection to localhost port 9025 [tcp/swa-3] succeeded!

and in the process running the server we see:

handler error: read tcp 127.0.0.1:9025->127.0.0.1:62501: read: connection reset by peer

@emersion
Copy link
Owner

I can't reproduce this.

@foxcpp
Copy link
Collaborator

foxcpp commented Jan 29, 2024

Similar issue reported for maddy: foxcpp/maddy#646

2023-11-09T15:17:40.094Z smtp: handler error: EOF	
2023-11-09T15:17:52.242Z smtp: handler error: EOF	
2023-11-09T15:17:59.750Z smtp: 220 [MADDY-NAME] ESMTP Service Ready
2023-11-09T15:18:02.027Z smtp: 220 [MADDY-NAME] ESMTP Service Ready
2023-11-09T15:18:02.028Z smtp: handler error: read tcp [MADDY-IP]:1025->[OTHER-IP]:54266: read: connection reset by peer
2023-11-09T15:18:10.097Z smtp: handler error: EOF	
2023-11-09T15:18:22.238Z smtp: handler error: EOF	

I think at least EOF should be filtered out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants