zulip icon indicating copy to clipboard operation
zulip copied to clipboard

Set an optional max connection lifetime for SMTP connections

Open alexmv opened this issue 2 years ago • 9 comments

Zulip's email_senders worker process opens an SMTP connection on start-up, and re-checks that connection is still live with a NOOP command immediately before attempting to re-use it every time: https://github.com/zulip/zulip/blob/77fd03e426e75b5914bece7da46a3bbaa8121f17/zerver/worker/queue_processors.py#L735-L751 https://github.com/zulip/zulip/blob/77fd03e426e75b5914bece7da46a3bbaa8121f17/zerver/lib/send_email.py#L294-L331

However, some SMTP servers react poorly to long-lived connections, closing connections not based on idle time, but rather connection time. This can result in connections dropping mid-send, which leaves it unclear to Zulip if the message has been processed or not.

We should add a configuration option which controls the max lifetime (in minutes) which we will reuse an open SMTP connection. If the connection has been open longer than this threshold, we should close the old connection and re-open a new one. If the setting is 0, we should tear open and close SMTP connections as needed, and never keep them open.

We should probably default this setting to 0, because the connection keep-alive is an optimization that most small installs won't need.

alexmv avatar Apr 23 '22 00:04 alexmv

Hello @zulip/server-production members, this issue was labeled with the "area: production" label, so you may want to check it out!

zulipbot avatar Apr 23 '22 00:04 zulipbot

I'd like to try this one :) @zulipbot claim

tal66 avatar May 24 '22 12:05 tal66

Welcome to Zulip, @tal66! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:

As you work on this issue, you'll also want to refer to the Zulip code contribution guide, as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!

zulipbot avatar May 24 '22 12:05 zulipbot

@tal66 You have been unassigned from this issue because you have not made any updates for over 14 days. Please feel free to reclaim the issue if you decide to pick up again. Thanks!

zulipbot avatar Jun 10 '22 01:06 zulipbot

.

tal66 avatar Jun 10 '22 07:06 tal66

@zulipbot claim

qiqistyle avatar Mar 27 '23 05:03 qiqistyle

Hello @qiqistyle, it looks like you've currently claimed 1 issue in this repository. We encourage new contributors to focus their efforts on at most 1 issue at a time, so please complete your work on your other claimed issues before trying to claim this issue again.

We look forward to your valuable contributions!

zulipbot avatar Mar 27 '23 05:03 zulipbot

@zulipbot claim

swayam0322 avatar Feb 03 '24 12:02 swayam0322

@swayam0322 You have been unassigned from this issue because you have not made any updates for over 14 days. Please feel free to reclaim the issue if you decide to pick up again. Thanks!

zulipbot avatar Feb 17 '24 07:02 zulipbot

We should probably default this setting to 0, because the connection keep-alive is an optimization that most small installs won't need.

Should we keep the default as None in the beginning? where None defaults to the existing behaviour of not closing the connection. This might help to avoid any unexpected changes for people with large-ish installs. Or would this setting only impact zulip cloud in a meaningful way?

shubham-padia avatar Jun 03 '24 13:06 shubham-padia