Wietse Venema:
> Juliana Rodrigueiro:
> > > To get rid of the 2s delays:
> > >
> > > /etc/postfix/main.cf:
> > >     lmtp_connection_cache_on_demand = no
> > >
> > > Please let us know if that helps. Meanwhile we can develop a proper fix.
> >
> > And yes, it worked, that helped a lot. Although not as fast as before, but
> > now I see only reasonable delays.
> >
> > Thank you very much for looking into it!!!
> 
> And thank you for your thorough investigation that helped to narrow
> down the root cause: under high traffic conditions, LMTP connections
> are cached but never reused, therefore those idle cached connections
> are exhausting server resources.

This is a patch for LMTP connection reuse over UNIX-domain sockets.

        Bugfix (introduced: Postfix 3.0): LMTP connections over
        UNIX-domain sockets were cached but not reused, due to a
        cache lookup key mismatch. Therefore, idle cached connections
        could exhaust LMTP server resources, resulting in two-second
        pauses between email deliveries. This problem was investigated
        by Juliana Rodrigueiro. File: smtp/smtp_connect.c.

Attached are two diffs: one for Postfix versions 3.0-3.5, and one
for Postfix versions 3.4 and 3.5.

These diffs are identical except that in Postfix 3.4 some macros
were renamed to better match their purpose.

Tested with Postfix 3.5. Please give it a try.

        wietse
diff -ur /var/tmp/postfix-3.1.11/src/smtp/smtp_connect.c ./src/smtp/smtp_connect.c
--- /var/tmp/postfix-3.1.11/src/smtp/smtp_connect.c	2015-03-29 15:04:22.000000000 -0400
+++ ./src/smtp/smtp_connect.c	2019-03-28 19:20:20.000000000 -0400
@@ -487,6 +487,8 @@
      * the "unix:" prefix.
      */
     smtp_cache_policy(state, path);
+    if (state->misc_flags & SMTP_MISC_FLAG_CONN_CACHE_MASK)
+	SET_NEXTHOP_STATE(state, dest);
 
     /*
      * Here we ensure that the iter->addr member refers to a copy of the
@@ -562,6 +564,12 @@
 	    msg_panic("%s: unix-domain destination not final!", myname);
 	smtp_cleanup_session(state);
     }
+
+    /*
+     * Cleanup.
+     */
+    if (HAVE_NEXTHOP_STATE(state))
+	FREE_NEXTHOP_STATE(state);
 }
 
 /* smtp_scrub_address_list - delete all cached addresses from list */
diff -ur /var/tmp/postfix-3.5-20190312/src/smtp/smtp_connect.c ./src/smtp/smtp_connect.c
--- /var/tmp/postfix-3.5-20190312/src/smtp/smtp_connect.c	2018-11-19 19:51:37.000000000 -0500
+++ ./src/smtp/smtp_connect.c	2019-03-28 18:58:04.000000000 -0400
@@ -492,6 +492,8 @@
      * the "unix:" prefix.
      */
     smtp_cache_policy(state, path);
+    if (state->misc_flags & SMTP_MISC_FLAG_CONN_CACHE_MASK)
+	SET_SCACHE_REQUEST_NEXTHOP(state, path);
 
     /*
      * Here we ensure that the iter->addr member refers to a copy of the
@@ -567,6 +569,12 @@
 	    msg_panic("%s: unix-domain destination not final!", myname);
 	smtp_cleanup_session(state);
     }
+
+    /*
+     * Cleanup.
+     */
+    if (HAVE_SCACHE_REQUEST_NEXTHOP(state))
+	CLEAR_SCACHE_REQUEST_NEXTHOP(state);
 }
 
 /* smtp_scrub_address_list - delete all cached addresses from list */

Reply via email to