[GH-ISSUE #10] Errors returned by smtpd.Server.ListenAndServe() are ignored #4

Closed
opened 2026-02-26 18:32:55 +03:00 by kerem · 1 comment
Owner

Originally created by @JonathonReinhart on GitHub (Feb 15, 2021).
Original GitHub issue: https://github.com/decke/smtprelay/issues/10

Problem

Any errors returned by ListenAndServe() are ignored.

For example, trying to run as an unprivileged user:

$ ./smtprelay -logfile smtprelay.log
2021/02/15 01:03:28 Listen on 127.0.0.1:25 ...
2021/02/15 01:03:28 Listen on [::1]:25 ...

The server runs and looks like it is listening, but it is is not (because binding to port 25 is a privileged operation). This is confirmed by looking at lsof -p $(pidof smtprelay) or ss -tnlp.

Cause

The cause is simple: ListenAndServe() is invoked as a goroutine and the return value is lost.

Originally created by @JonathonReinhart on GitHub (Feb 15, 2021). Original GitHub issue: https://github.com/decke/smtprelay/issues/10 # Problem Any errors returned by `ListenAndServe()` are ignored. For example, trying to run as an unprivileged user: ``` $ ./smtprelay -logfile smtprelay.log 2021/02/15 01:03:28 Listen on 127.0.0.1:25 ... 2021/02/15 01:03:28 Listen on [::1]:25 ... ``` The server runs and looks like it is listening, but it is is not (because binding to port 25 is a privileged operation). This is confirmed by looking at `lsof -p $(pidof smtprelay)` or `ss -tnlp`. # Cause The cause is simple: [`ListenAndServe()` is invoked as a goroutine](https://github.com/decke/smtprelay/blob/0e8986ca79f94792343d93027ff28352bd1c212c/main.go#L259) and the return value is lost.
kerem closed this issue 2026-02-26 18:32:55 +03:00
Author
Owner

@decke commented on GitHub (Feb 16, 2021):

Thanks for the fix!

<!-- gh-comment-id:779877585 --> @decke commented on GitHub (Feb 16, 2021): Thanks for the fix!
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/smtprelay#4
No description provided.