element-hq / element-hq/synapse
Synapse sends SMTP retries in quick succession if SMTP server is down
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
This issue has been migrated from [#8145](https://github.com/matrix-org/synapse/issues/8145).
---
### Description
If the SMTP server doesn't work perfectly for some reason, Synapse starts a Denial-of-Service (DoS) attack on that server. This triggers spam/DoS protection like Fail2Ban or UFW 'limit' rules on the server, of course, putting the Synapse server onto a temporary or permanent blacklist (on the SMTP server).
### Steps to reproduce
- Stop the configured mail server (to imitate some malfunction).
- Using a client (e.g. Riot/Elements), attempt to do something sending an email. For example, adding an email address to a user account.
After doing so, one can find this in the logs, 5 "retries" within less than 0.1 seconds:
```
2020-07-31 15:02:14,371 - synapse.push.mailer - 301 - INFO - POST-11 - Sending email to mah@jump-ing.de
2020-07-31 15:02:14,668 - twisted - 192 - INFO - - SMTP Client retrying server. Retry: 5
2020-07-31 15:02:14,684 - twisted - 192 - INFO - - SMTP Client retrying server. Retry: 4
2020-07-31 15:02:14,702 - twisted - 192 - INFO - - SMTP Client retrying server. Retry: 3
2020-07-31 15:02:14,718 - twisted - 192 - INFO - - SMTP Client retrying server. Retry: 2
2020-07-31 15:02:14,736 - twisted - 192 - INFO - - SMTP Client retrying server. Retry: 1
```
Blindly retrying to connect to a SMTP server is entirely pointless. SMTP uses TCP/IP, which is a reliable protocol (it retries on its own on errors), so there are no network errors one can work around by retrying immediately. Retrying only makes sense after looking at the error and acting sensible on that. In case one can't connect at all, it makes no sense to try again within less than a couple of minutes.
### Version information
- **Homeserver**:
localhost
- **Version**:
```
$ curl http://localhost:8008/_synapse/admin/v1/server_version
{
"python_version": "3.7.3",
"server_version": "1.19.0"
}
```
- **Install method**:
`apt-get install matrix-synapse-py3` with matrix.org's repository (https://packages.matrix.org/debian/) installed.
- **Platform**:
Debian 10.5 _buster_ on a virtual machine (in order to test before rolling out to a public server).
Contributor guide
Assessment
This issue has not been assessed yet.