mhale / smtpd

An SMTP server package written in Go, in the style of the built-in HTTP server.
The Unlicense
404 stars 92 forks source link

Add listener tracking and listener closing on close/shutdown #31

Closed cuu508 closed 1 year ago

cuu508 commented 3 years ago

In relation to #27, here's my attempt to fix server shutdown of an idle server.

I looked at net.http and used the same approach. I copied trackListener and closeListeners from net.http almost as-is (added a note in README about it).

The idea:

This PR needs a review. I'm new to Go, and would not be aware of any subtle bugs this may be introducing.

One particular thing I'm not sure about is the listener closing function. In net.http, it is called "closeListenersLocked". The "Locked" part must have some significance, but I'm not sure what exactly. In general, I suspect the Close and Shutdown methods may have thread safety problems.

goenning commented 2 years ago

hey @cuu508 have you been using this code in production? How's it behaving?

there's already a unit test for shutdown, I think it'd be useful to have a test for this scenario as well so there's no regression

cuu508 commented 2 years ago

Hi @goenning, I am not using it in production. I did test my changes with the one production app that I have, and it seemed to work OK, but I didn't deploy it for two reasons: