Truncate delay when peer closes connection. Bug 348
authorJeremy Harris <jgh146exb@wizmail.org>
Mon, 8 Jun 2015 20:48:50 +0000 (21:48 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Mon, 8 Jun 2015 21:50:21 +0000 (22:50 +0100)
This is now possible on Linux, at least.

src/src/acl.c
test/confs/0609 [new file with mode: 0644]
test/log/0552
test/log/0609 [new file with mode: 0644]
test/runtest
test/scripts/0000-Basic/0552
test/scripts/0000-Basic/0609 [new file with mode: 0644]
test/stderr/0609 [new file with mode: 0644]
test/stdout/0609 [new file with mode: 0644]

index e79c87f..dae3101 100644 (file)
@@ -3480,6 +3480,34 @@ for (; cb != NULL; cb = cb->next)
             debug_printf("delay skipped in -bh checking mode\n");
           }
 
+       /* NOTE 1: Remember that we may be
+        dealing with stdin/stdout here, in addition to TCP/IP connections.
+        Also, delays may be specified for non-SMTP input, where smtp_out and
+        smtp_in will be NULL. Whatever is done must work in all cases.
+
+        NOTE 2: The added feature of flushing the output before a delay must
+        apply only to SMTP input. Hence the test for smtp_out being non-NULL.
+        */
+
+        else
+          {
+          if (smtp_out != NULL && !disable_delay_flush)
+           mac_smtp_fflush();
+
+#if !defined(NO_POLL_H) && defined (_GNU_SOURCE)
+           {
+           struct pollfd p;
+           nfds_t n = 0;
+           if (smtp_out)
+             {
+             p.fd = fileno(smtp_out);
+             p.events = POLLRDHUP;
+             n = 1;
+             }
+           if (poll(&p, n, delay*1000) > 0)
+             HDEBUG(D_acl) debug_printf("delay cancelled by peer close\n");
+           }
+#else
         /* It appears to be impossible to detect that a TCP/IP connection has
         gone away without reading from it. This means that we cannot shorten
         the delay below if the client goes away, because we cannot discover
@@ -3489,20 +3517,10 @@ for (; cb != NULL; cb = cb->next)
         Exim process is not held up unnecessarily. However, it seems that we
         can't. The poll() function does not do the right thing, and in any case
         it is not always available.
-
-        NOTE 1: If ever this state of affairs changes, remember that we may be
-        dealing with stdin/stdout here, in addition to TCP/IP connections.
-        Also, delays may be specified for non-SMTP input, where smtp_out and
-        smtp_in will be NULL. Whatever is done must work in all cases.
-
-        NOTE 2: The added feature of flushing the output before a delay must
-        apply only to SMTP input. Hence the test for smtp_out being non-NULL.
         */
 
-        else
-          {
-          if (smtp_out != NULL && !disable_delay_flush) mac_smtp_fflush();
           while (delay > 0) delay = sleep(delay);
+#endif
           }
         }
       }
diff --git a/test/confs/0609 b/test/confs/0609
new file mode 100644 (file)
index 0000000..d6ac511
--- /dev/null
@@ -0,0 +1,47 @@
+# Exim test configuration 0609
+# Long ACL delays
+
+SERVER=
+
+exim_path = EXIM_PATH
+host_lookup_order = bydns
+primary_hostname = myhost.test.ex
+spool_directory = DIR/spool
+log_file_path = DIR/spool/log/SERVER%slog
+gecos_pattern = ""
+gecos_name = CALLER_NAME
+
+# ----- Main settings -----
+
+disable_ipv6 = true
+
+acl_smtp_rcpt = delay4_accept
+log_selector = +smtp_connection
+#hosts_connection_nolog = : 127.0.0.1
+
+
+# ----- ACLs -----
+
+begin acl
+
+delay4_accept:
+  accept   delay = 4s
+
+# ----- Routers -----
+
+begin routers
+
+accept:
+  driver = accept
+  transport = appendfile
+
+# ----- Transports -----
+
+begin transports
+
+appendfile:
+  driver = appendfile
+  file = DIR/test-mail/$local_part
+  user = CALLER
+
+# End
index 8148c5a..d070f9c 100644 (file)
@@ -14,6 +14,6 @@
 
 ******** SERVER ********
 1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225
-1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225
 1999-03-02 09:44:33 SMTP connection from localhost (myhost.test.ex) [127.0.0.1] lost while reading message data (header)
+1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225
 1999-03-02 09:44:33 10HmaY-0005vi-00 <= CALLER@myhost.test.ex H=localhost (myhost.test.ex) [127.0.0.1] P=esmtp S=sss id=E10HmaX-0005vi-00@myhost.test.ex
diff --git a/test/log/0609 b/test/log/0609
new file mode 100644 (file)
index 0000000..a19051a
--- /dev/null
@@ -0,0 +1,7 @@
+
+******** SERVER ********
+1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225
+1999-03-02 09:44:33 SMTP connection from [127.0.0.1] (TCP/IP connection count = 1)
+1999-03-02 09:44:33 SMTP connection from [127.0.0.1] closed by QUIT
+1999-03-02 09:44:33 SMTP connection from [127.0.0.1] (TCP/IP connection count = 1)
+1999-03-02 09:44:33 unexpected disconnection while reading SMTP command from [127.0.0.1]
index 616ded3..df6132b 100755 (executable)
@@ -1378,6 +1378,9 @@ $munges =
     'tls_anycipher' =>
     { 'mainlog' => 's/ X=TLS\S+ / X=TLS_proto_and_cipher /' },
 
+    'debug_pid' =>
+    { 'stderr' => 's/\d{1,5}/ppppp/g' },
+
   };
 
 
index 1958dbe..a0621ca 100644 (file)
@@ -11,6 +11,7 @@ exim -DSERVER=server -DDDF=control=no_delay_flush -bd -oX PORT_D
 exim -qf
 ****
 killdaemon
+sleep 1
 # This daemon should flush before delaying
 exim -DSERVER=server -bd -oX PORT_D
 ****
diff --git a/test/scripts/0000-Basic/0609 b/test/scripts/0000-Basic/0609
new file mode 100644 (file)
index 0000000..84ab89d
--- /dev/null
@@ -0,0 +1,29 @@
+# Long ACL delay, truncated
+munge debug_pid
+need_ipv4
+#
+# We want the debug note of a truncated delay
+exim -d-all+acl -DSERVER=server -odq -bd -oX PORT_D
+****
+#
+# Server delays 4s before accepting RCPT
+client 127.0.0.1 PORT_D
+??? 220
+mail from:<x@y.test.ex>
+??? 250
+rcpt to:<delay4_accept@y.test.ex>
+??? 250
+quit
+??? 221
+****
+#
+# Server delays 4s before accepting RCPT
+# but client closes connection
+client 127.0.0.1 PORT_D
+??? 220
+mail from:<x@y.test.ex>
+??? 250
+rcpt to:<delay4_accept@y.test.ex>
+****
+killdaemon
+no_msglog_check
diff --git a/test/stderr/0609 b/test/stderr/0609
new file mode 100644 (file)
index 0000000..99a0475
--- /dev/null
@@ -0,0 +1,52 @@
+
+******** SERVER ********
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+admin user
+ppppp daemon_smtp_port overridden by -oX:
+ppppp   <: ppppp
+ppppp listening on all interfaces (IPvppppp) port ppppp
+ppppp pid written to TESTSUITE/spool/exim-daemon.pid
+ppppp LOG: MAIN
+ppppp   exim x.yz daemon started: pid=ppppp, no queue runs, listening for SMTP on port ppppp (IPvppppp)
+ppppp daemon running with uid=ppppp gid=ppppp euid=ppppp egid=ppppp
+ppppp Listening...
+ppppp Connection request from ppppp.ppppp.ppppp.ppppp port ppppp
+ppppp LOG: smtp_connection MAIN
+ppppp   SMTP connection from [ppppp.ppppp.ppppp.ppppp] (TCP/IP connection count = ppppp)
+ppppp ppppp SMTP accept process running
+ppppp Listening...
+ppppp Process ppppp is handling incoming connection from [ppppp.ppppp.ppppp.ppppp]
+ppppp Process ppppp is ready for new message
+ppppp using ACL "delayppppp_accept"
+ppppp processing "accept"
+ppppp check delay = ppppps
+ppppp delay modifier requests ppppp-second delay
+ppppp accept: condition test succeeded in ACL "delayppppp_accept"
+ppppp end of ACL "delayppppp_accept": ACCEPT
+ppppp LOG: smtp_connection MAIN
+ppppp   SMTP connection from [ppppp.ppppp.ppppp.ppppp] closed by QUIT
+ppppp child ppppp ended: status=pppppxppppp
+ppppp   normal exit, ppppp
+ppppp ppppp SMTP accept processes now running
+ppppp Listening...
+ppppp Connection request from ppppp.ppppp.ppppp.ppppp port ppppp
+ppppp LOG: smtp_connection MAIN
+ppppp   SMTP connection from [ppppp.ppppp.ppppp.ppppp] (TCP/IP connection count = ppppp)
+ppppp ppppp SMTP accept process running
+ppppp Listening...
+ppppp Process ppppp is handling incoming connection from [ppppp.ppppp.ppppp.ppppp]
+ppppp Process ppppp is ready for new message
+ppppp using ACL "delayppppp_accept"
+ppppp processing "accept"
+ppppp check delay = ppppps
+ppppp delay modifier requests ppppp-second delay
+ppppp delay cancelled by peer close
+ppppp accept: condition test succeeded in ACL "delayppppp_accept"
+ppppp end of ACL "delayppppp_accept": ACCEPT
+ppppp LOG: lost_incoming_connection MAIN
+ppppp   unexpected disconnection while reading SMTP command from [ppppp.ppppp.ppppp.ppppp]
+ppppp child ppppp ended: status=pppppxppppp
+ppppp   normal exit, ppppp
+ppppp ppppp SMTP accept processes now running
+ppppp Listening...
diff --git a/test/stdout/0609 b/test/stdout/0609
new file mode 100644 (file)
index 0000000..8ebf9a2
--- /dev/null
@@ -0,0 +1,21 @@
+Connecting to 127.0.0.1 port 1225 ... connected
+??? 220
+<<< 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+>>> mail from:<x@y.test.ex>
+??? 250
+<<< 250 OK
+>>> rcpt to:<delay4_accept@y.test.ex>
+??? 250
+<<< 250 Accepted
+>>> quit
+??? 221
+<<< 221 myhost.test.ex closing connection
+End of script
+Connecting to 127.0.0.1 port 1225 ... connected
+??? 220
+<<< 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+>>> mail from:<x@y.test.ex>
+??? 250
+<<< 250 OK
+>>> rcpt to:<delay4_accept@y.test.ex>
+End of script