Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email tests fail with "Error sending threepid validation email to testemail@example.com" #1048

Closed
anoadragon453 opened this issue May 24, 2021 · 9 comments

Comments

@anoadragon453
Copy link
Member

anoadragon453 commented May 24, 2021

The following tests seem to fail when running on some people's local machines:

  • Can register using an email address
  • Can login with 3pid and password using m.login.password
  • After deactivating account, can't log in with an email

These tests run fine in CI, but locally they fail with the following stacktrace in Synapse's log:

2021-05-24 11:22:41,490 - twisted - 258 - INFO - sentinel - SMTP Client retrying server. Retry: 5
2021-05-24 11:22:41,491 - twisted - 258 - INFO - sentinel - SMTP Client retrying server. Retry: 4
2021-05-24 11:22:41,492 - twisted - 258 - INFO - sentinel - SMTP Client retrying server. Retry: 3
2021-05-24 11:22:41,492 - twisted - 258 - INFO - sentinel - SMTP Client retrying server. Retry: 2
2021-05-24 11:22:41,493 - twisted - 258 - INFO - sentinel - SMTP Client retrying server. Retry: 1
2021-05-24 11:22:41,493 - synapse.handlers.identity - 415 - ERROR - POST-16 - Error sending threepid validation email to testemail@example.com
Traceback (most recent call last):
  File "/home/callum/sources/synapse/synapse/handlers/identity.py", line 413, in send_threepid_validation
    await send_email_func(email_address, token, client_secret, session_id)
  File "/home/callum/sources/synapse/synapse/push/mailer.py", line 170, in send_registration_mail
    await self.send_email(
  File "/home/callum/sources/synapse/synapse/push/mailer.py", line 318, in send_email
    await self.send_email_handler.send_email(
  File "/home/callum/sources/synapse/synapse/handlers/send_email.py", line 85, in send_email
    await make_deferred_yieldable(
twisted.internet.error.ConnectionRefusedError: Connection was refused by other side: 111: Connection refused.

It appears that Synapse is unable to send an email through the fake SMTP server that Sytest spins up. I'm not sure whether this is due to the SMTP server failing to start/listen for connections (perhaps I'm missing a Perl or Python dependency?), or an issue with Synapse's configuration.

cc @richvdh as I believe he wrote the SMTP server impl. for sytest.

@govynnus
Copy link
Contributor

I think it's to do with localhost resolving to IPv4, while the SMTP server listens on IPv6.

@govynnus
Copy link
Contributor

Yep, all tests pass with:

diff --git a/tests/04mail-server.pl b/tests/04mail-server.pl
index 99d33e92..e118c5f0 100644
--- a/tests/04mail-server.pl
+++ b/tests/04mail-server.pl
@@ -33,6 +33,7 @@ our $MAIL_SERVER_INFO = fixture(
       $loop->add( $mail_server );

       $mail_server->listen(
+         family   => "inet",
          host     => $BIND_HOST,
          service  => 0,
          socktype => 'stream',

Related: matrix-org/synapse#7720

@richvdh
Copy link
Member

richvdh commented May 24, 2021

that's odd. localhost should work over IPv6:

rav@fred:~$ ping6 localhost
PING localhost(ip6-localhost (::1)) 56 data bytes
64 bytes from ip6-localhost (::1): icmp_seq=1 ttl=64 time=0.079 ms

@govynnus
Copy link
Contributor

It might be that my networking isn't set up quite correctly.

If I do ./run-tests.pl -w tests/11register.pl, then in a separate terminal:

$ telnet localhost <smtp_port>
telnet: can't connect to remote host (127.0.0.1): Connection refused
$ telnet ::1 46869
Connected to ::1
220 Sytest test server

@anoadragon453
Copy link
Member Author

@govynnus Do you have:

::1        localhost

in your /etc/hosts file?

@govynnus
Copy link
Contributor

Yep. ping6 localhost works fine.

@anoadragon453
Copy link
Member Author

Is it worth trying to make Sytest listen on IPv4, or should we just track this in matrix-org/synapse#7720?

@richvdh
Copy link
Member

richvdh commented Jul 6, 2021

If matrix-org/synapse#7720 is the only reason for the failure, I would rather see that fixed.

@clokep
Copy link
Member

clokep commented Aug 29, 2023

The upstream Synapse bug (matrix-org/synapse#7720) has been fixed. I'm going to close this with the assumption that it has fixed the sytest issue. If this is still seen when running sytest, please reopen.

@clokep clokep closed this as completed Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants