File: 0002-Shutdown-and-close-sockets-cleanly.patch

package info (click to toggle)
cyrus-imapd 3.10.1-3~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 59,016 kB
  • sloc: ansic: 284,365; perl: 137,046; javascript: 9,659; sh: 5,730; yacc: 2,565; makefile: 2,186; cpp: 2,147; lex: 662; xml: 621; awk: 303; python: 272; asm: 262
file content (73 lines) | stat: -rw-r--r-- 1,819 bytes parent folder | download | duplicates (3)
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);