1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
Description: Shutdown and close sockets cleanly
Cleanly shutdown and close sockets, this is supposed to allow for better
TCP teardown on the remote end, and reduces CLOSE_WAIT time.
.
This patch was written 8 years ago, it is possible that nowadays nothing
will benefit from a shutdown() right before close(). The commit log
from eight years ago mentions that SHUT_RD should be upgraded to
SHUT_RDWR where possible, but only after verification that this is not
going to cause problems (e.g. by discarding data still on flight to the
remote).
.
Also, it is possible that new daemons and utils in Cyrus 2.2 and 2.3 may
need similar patches.
Author: Henrique de Moraes Holschuh <hmh@debian.org>
Forwarded: https://github.com/cyrusimap/cyrus-imapd/pull/3278
Reviewed-By: Xavier Guimard <yadd@debian.org
Last-Update: 2020-02-10
--- a/imap/fud.c
+++ b/imap/fud.c
@@ -145,6 +145,15 @@
seen_done();
closelog();
cyrus_done();
+
+ /* be nice to remote */
+ shutdown(0, SHUT_RD);
+ shutdown(1, SHUT_RD);
+ shutdown(2, SHUT_RD);
+ close(0);
+ close(1);
+ close(2);
+
exit(code);
}
--- a/imap/imapd.c
+++ b/imap/imapd.c
@@ -1363,6 +1363,10 @@
#ifdef HAVE_SSL
tls_shutdown_serverengine();
#endif
+ /* shutdown socket nicely */
+ cyrus_close_sock(0);
+ cyrus_close_sock(1);
+ cyrus_close_sock(2);
saslprops_free(&saslprops);
--- a/imap/lmtpd.c
+++ b/imap/lmtpd.c
@@ -1086,6 +1086,9 @@
cyrus_done();
+ /* shutdown socket nicely */
+ cyrus_reset_stdio();
+
exit(code);
}
--- a/imap/pop3d.c
+++ b/imap/pop3d.c
@@ -660,6 +660,9 @@
saslprops_free(&saslprops);
cyrus_done();
+ cyrus_close_sock(0);
+ cyrus_close_sock(1);
+ cyrus_close_sock(2);
if (config_iolog) {
read_io_count(io_count_stop);
|