[Mailman-Developers] [Patch] SMTPDirect.py wrongly closing the connection

Marc MERLIN marc_news@valinux.com
Sat, 15 Dec 2001 21:45:09 -0800


On Fri, Dec 14, 2001 at 03:08:20AM -0500, Barry A. Warsaw wrote:
> 
> >>>>> "MM" == Marc MERLIN <marc_news@vasoftware.com> writes:
> 
>     MM> So, I have my mailman alpha 3 cvs with python 2.1 seemingly
>     MM> working, and when I move a list with more than one subscriber
>     MM> to it
> 
> Exactly how many subscribers are on your list?  Is it more than
> SMTP_MAX_RCPTS?  I hope your answer is "yes"!
 
The answer is "No".
The reason mailman does two chunks is the new code that splits per top tld.
I did a test with foo.org and bar.com, which caused to chunks and two
separate deliveries to the MTA
 
> SMTPDirect tries to reuse a connection to the smtpd when delivering
> multiple chunks.  

Yes

> The code in deliver() as it currently stands will do > the following:
> 
> - On the first chunk, it finds its socket isn't connected, so it
>   connects, doing the EHLO/HELO dance
> - Then it calls conn.sendmail() which does the MAIL FROM/RCPT TO/DATA
>   dance
> - Then the finally clause executes and a QUIT is issued.  The server
>   closes the connection, as it must (RFC 2821).
> - Now the next chunk comes along and we find the socket is not
>   connected, so we re-connect.  Note that we're using the same
>   smtplib.SMTP object, but we're getting a new socket connection
> - The state in the SMTP object thinks it's already issued an EHLO and
>   so doesn't issue it again.  Instead, when this time it calls
>   sendmail() it jumps right to MAIL FROM and boom, you're hosed.
 
Yes, that's where I'm seeing the problem, and confirmed with running exim in
debug mode. The  when the second batch  is about to be  delivered, the first
thing exim sees on the new connection is MAIL FROM (no EHLO).

> Your patch eliminates the QUIT in the finally clause and so when the
> the first transaction in the session completes, the session won't be
> QUIT, the socket won't be closed, and the second sendmail() call
> succeeds.

Yes, that's what I intended to do :-)

> Interestingly enough, it looks like Postfix isn't bothered by the lack
> of EHLO/HELO at the start of the second session.  This behavior
> appears to be controlled by the smtpd_helo_required config variable
> which seems to default to "no".  Can you guess why I never noticed
> this bug before? :)
 
Yeah, I figured that most MTAs would allow the mail anyway (probably exim
too if you turn off the paranoia checks)
 
> Your patch clearly gets to the heart of the matter: in a multiple
> transaction session, we mustn't issue a QUIT until the session is
> over.  So SMTPDirect.py is broken.  I'm not sure your patch is
> entirely correct -- I need to trace the code through both the

Neither am I. Mailman  just works a lot  better with it on my  system, but I
knew  there was  something cleaner  (especially because  my mailman  doesn't
really close the connection, it just drops the socket when the program ends)

> non-threaded and threaded delivery paths and think about the error
> conditions.  Probably the whole try/finally bit can be removed, and
> .quit() needs to be called when we're really done with the
> connection.  Attached is a patch that I think will do the trick, but I
> haven't tested it yet.

I tried it, and it seems to work fine. I now also get:
2001-12-15 21:45:07 SMTP connection from localhost (moremagic.merlins.org)
[127.0.0.1] closed by QUIT

> Now, if you tell me that the # of recips is < SMTP_MAX_RCPTS, then
> none of this analysis is relevant, and I can't see how you're getting
> this problem. ;)
 
It's all right, you forgot the code that splits by TLDs :-)
 
> Oh sure, rub it in!  We're still unseasonably warm here in DC, even if
> we have gotten below 70 deg F the last few days.  No sign of snow so

Kirkwood in California current has the deepest snow base in all of the US
(185 inches, but who's counting :-D)

> far, so I hope you think about Mailman on all the lifts up the

(typing in the car on the way back)
Ummh, sure, I was thinking about the patch while wrestling with the deep
fresh powder :-)))

> P.S. Python 2.2 rc 1 release tomorrow, er, later today.  Hopefully
> some Mailman catch up time this weekend.

Good to hear that :-)

Marc
-- 
Microsoft is to operating systems & security ....
                                      .... what McDonalds is to gourmet cooking
  
Home page: http://marc.merlins.org/   |   Finger marc_f@merlins.org for PGP key