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

Caught connection error in SMTP (localhost:1587) : <class 'ssl.SSLError'> with message: ac.robinson.email-oauth2-proxy #121

Closed
brianjmurrell opened this issue Jan 11, 2023 · 20 comments · Fixed by #128

Comments

@brianjmurrell
Copy link
Contributor

I frequently get:

2023-01-10 21:57:50: Caught connection error in SMTP (localhost:1587) : <class 'ssl.SSLError'> with message: ac.robinson.email-oauth2-proxy
2023-01-10 21:57:50: Is the server's `starttls` setting correct? Current value: True
2023-01-10 21:57:50: If you encounter this error repeatedly, please check that you have correctly configured python root certificates; see: https://github.com/simonrob/email-oauth2-proxy/issues/14

But this only happens a while after I have successfully authorized an O365 account and have successfully sent mail through it so it doesn't seem like it could/should be #14. And then a while later it might go back to being successful again, but then complaining again:

2023-01-10 22:06:44: SMTP (localhost:1587; [redacted]) [ Successfully authenticated SMTP connection - releasing session ]
2023-01-10 22:16:42: Caught connection error in SMTP (localhost:1587) : <class 'ssl.SSLError'> with message: ac.robinson.email-oauth2-proxy
2023-01-10 22:16:42: Is the server's `starttls` setting correct? Current value: True
2023-01-10 22:16:42: If you encounter this error repeatedly, please check that you have correctly configured python root certificates; see: https://github.com/simonrob/email-oauth2-proxy/issues/14

Any ideas?

@nbdd0121
Copy link

I got exactly this error yesterday. Changed MAX_SSL_HANDSHAKE_ATTEMPTS to 0 fixed the issue.

@simonrob
Copy link
Owner

Setting MAX_SSL_HANDSHAKE_ATTEMPTS removes the handshake timeout limit. Are you finding that the connection succeeds with a higher limit (i.e., the handshake is taking longer than expected), or are you perhaps just suppressing the error by doing this? (Add a log message after this line to find out).

I suspect this may be related to #118, though don't have any particular suggestions beyond the ones listed there as I cannot replicate this myself. If you can isolate the issue and find a way to replicate it reliably that would be really helpful.

@nbdd0121
Copy link

I wouldn't call MAX_SSL_HANDSHAKE_ATTEMPTS a timeout; it is incremented every time there's a read/write event. I believe read/write event can be repeated called if there is unconsumed data associated with the socket. So in a situation where e.g. the plain-text SMTP client sends data before handshake completes, the counter will quickly deplete due to unread data in the socket.

@simonrob
Copy link
Owner

It is not technically a timeout in that sense (it does not measure time as such), but it is used as a way to to abort connections where the SSL handshake seems to be failing. SMTP connections prior to STARTTLS shouldn't be affected because they are marked as an insecure connection until the STARTTLS command is received. Only reads/writes relating to the handshake are included when incrementing this counter.

@brianjmurrell
Copy link
Contributor Author

Add a log message after this line to find out.

I have not set MAX_SSL_HANDSHAKE_ATTEMPTS to 0 as @nbdd0121 but I did add a log message as you suggested above, regardless.

When I get the error reported here, the log message is not printed.

But clearly I am still seeing this issue. Any further diagnosis I can do?

@simonrob
Copy link
Owner

It may just be that your particular SMTP configuration is requiring more negotiation to complete the handshake. I haven't seen anywhere near as many as 2^16 (65,536; the default maximum that is used as a way to abort failed attempts) calls to the handshake function during a successful attempt, but @nbdd0121 is correct that this value is the source of the error you are seeing. What happens if you increase MAX_SSL_HANDSHAKE_ATTEMPTS to, say, 2^17 or 2^18?

@brianjmurrell
Copy link
Contributor Author

And/or we could just see how high the count could get. If I were to set it to say, 0 and then want to see what the count was when it was finally successful where would I put that Log? Would that go in the else: block or after

self.socket.do_handshake()
?

@simonrob
Copy link
Owner

You could add the count (self.ssl_handshake_attempts) to the TLS handshake complete message a few lines below?

@brianjmurrell
Copy link
Contributor Author

Interesting variation in counts:

2023-01-18 07:26:01: SMTP (localhost:1587) Attemps to complete SSL handshake: 12125
2023-01-18 07:26:01: SMTP (localhost:1587) Attemps to complete SSL handshake: 11479
2023-01-18 07:26:01: SMTP (localhost:1587) Attemps to complete SSL handshake: 12109
2023-01-18 07:26:01: SMTP (localhost:1587) Attemps to complete SSL handshake: 1
2023-01-18 07:26:01: SMTP (localhost:1587) Attemps to complete SSL handshake: 1
2023-01-18 07:26:01: SMTP (localhost:1587) Attemps to complete SSL handshake: 1

@simonrob
Copy link
Owner

I would guess that the ~12k ones are during STARTTLS negotiation, and the subsequent one is in a send or recv that required additional data to be sent (which is normal – ssl.SSLWantReadError or ssl.SSLWantWriteError).

Regardless, these are all well below 65,536. What is the value when you get the error?

@brianjmurrell
Copy link
Contributor Author

brianjmurrell commented Jan 18, 2023

I just had one hit 68,010 and yet another at 67,473. Both were followed immediately by a value of 1.

@simonrob
Copy link
Owner

simonrob commented Jan 18, 2023

Seeing additional handshakes (the 1 and other low values) both straight after the initial handshake and also periodically after that is expected, but the current default maximum value was decided based solely on my own testing, and I'm perfectly happy to increase it.

Could you keep track of the values you get over a few days and suggest a new higher maximum?

simonrob added a commit that referenced this issue Jan 19, 2023
Slow/unreliable connections can reach `MAX_SSL_HANDSHAKE_ATTEMPTS` before the handshake has completed; this allows more time for completion in that case, but still catches misconfigured connections.
See #121.
@simonrob
Copy link
Owner

Reading through the other issue you have open, I realised that poor network connectivity might be part of the issue here – on a slow or unreliable connection, it could easily be possible for the handshake method to be called enough times to unintentionally pass the threshold. So, the issue-121 branch adds a 1ms delay each time this method returns in a "want read" or "want write" state. This should have essentially zero impact on fast connections, but does resolve the issue for me on simulated slower or intermittent networks.

Please could you try this branch?

@brianjmurrell
Copy link
Contributor Author

Could you keep track of the values you get over a few days and suggest a new higher maximum?

Sure.

What exactly is it that is happening anywhere from 1 to over 64K times? Is it an operation that should only ever happen once under ideal conditions and that it takes over 64K times sometime is indicating some kind of resource constraint that requires sometimes over 64K attempts to finally succeed?

@simonrob
Copy link
Owner

The proxy needs to begin the TLS handshake and wait for it to complete, but has no knowledge about the underlying protocol that is being used. The handshake duration can be variable, and it also requires negotiation with the remote server (i.e., network communication). For this reason, the handshake method is designed to be called repeatedly until it does not throw an error. See the documentation.

Please try the issue-121 branch, which adds a 1ms delay between failed handshake attempts.

@brianjmurrell
Copy link
Contributor Author

With the 1ms delay:

2023-01-19 09:19:10: SMTP (localhost:1587; 127.0.0.1:52560->smtp.office365.com:587) Attempts to complete SSL handshake: 329
2023-01-19 09:23:15: SMTP (localhost:1587; 127.0.0.1:49124->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-19 09:24:08: SMTP (localhost:1587; 127.0.0.1:37210->smtp.office365.com:587) Attempts to complete SSL handshake: 339
2023-01-19 09:29:49: SMTP (localhost:1587; 127.0.0.1:43746->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-19 09:35:15: SMTP (localhost:1587; 127.0.0.1:41850->smtp.office365.com:587) Attempts to complete SSL handshake: 343
2023-01-19 09:54:12: SMTP (localhost:1587; 127.0.0.1:39944->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-19 23:30:03: SMTP (localhost:1587; 127.0.0.1:36722->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-19 23:39:41: SMTP (localhost:1587; 127.0.0.1:52884->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-19 23:40:03: SMTP (localhost:1587; 127.0.0.1:50798->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-19 23:43:31: SMTP (localhost:1587; 127.0.0.1:56916->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-19 23:58:31: SMTP (localhost:1587; 127.0.0.1:44996->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 00:00:03: SMTP (localhost:1587; 127.0.0.1:38438->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 00:08:30: SMTP (localhost:1587; 127.0.0.1:59878->smtp.office365.com:587) Attempts to complete SSL handshake: 46
2023-01-20 00:08:30: SMTP (localhost:1587; 127.0.0.1:59896->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 00:08:30: SMTP (localhost:1587; 127.0.0.1:59888->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 00:10:03: SMTP (localhost:1587; 127.0.0.1:52732->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 00:18:30: SMTP (localhost:1587; 127.0.0.1:57162->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 00:20:03: SMTP (localhost:1587; 127.0.0.1:33782->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 00:23:30: SMTP (localhost:1587; 127.0.0.1:42350->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 00:28:30: SMTP (localhost:1587; 127.0.0.1:35654->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 00:38:31: SMTP (localhost:1587; 127.0.0.1:45208->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 00:40:03: SMTP (localhost:1587; 127.0.0.1:43956->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 00:48:30: SMTP (localhost:1587; 127.0.0.1:36646->smtp.office365.com:587) Attempts to complete SSL handshake: 50
2023-01-20 00:48:30: SMTP (localhost:1587; 127.0.0.1:36662->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 00:48:30: SMTP (localhost:1587; 127.0.0.1:36648->smtp.office365.com:587) Attempts to complete SSL handshake: 48
2023-01-20 00:48:30: SMTP (localhost:1587; 127.0.0.1:36668->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 00:50:03: SMTP (localhost:1587; 127.0.0.1:44636->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 00:58:31: SMTP (localhost:1587; 127.0.0.1:56990->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 00:58:31: SMTP (localhost:1587; 127.0.0.1:57016->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 00:58:31: SMTP (localhost:1587; 127.0.0.1:57002->smtp.office365.com:587) Attempts to complete SSL handshake: 48
2023-01-20 01:00:03: SMTP (localhost:1587; 127.0.0.1:34168->smtp.office365.com:587) Attempts to complete SSL handshake: 37
2023-01-20 01:03:30: SMTP (localhost:1587; 127.0.0.1:35618->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 01:10:03: SMTP (localhost:1587; 127.0.0.1:54384->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 01:13:30: SMTP (localhost:1587; 127.0.0.1:57584->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-20 01:20:03: SMTP (localhost:1587; 127.0.0.1:51566->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 01:23:30: SMTP (localhost:1587; 127.0.0.1:35642->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 01:28:31: SMTP (localhost:1587; 127.0.0.1:58476->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 01:28:31: SMTP (localhost:1587; 127.0.0.1:58472->smtp.office365.com:587) Attempts to complete SSL handshake: 46
2023-01-20 01:40:03: SMTP (localhost:1587; 127.0.0.1:43782->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 01:48:30: SMTP (localhost:1587; 127.0.0.1:49896->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 01:48:30: SMTP (localhost:1587; 127.0.0.1:49892->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 01:48:30: SMTP (localhost:1587; 127.0.0.1:49908->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 01:50:03: SMTP (localhost:1587; 127.0.0.1:35786->smtp.office365.com:587) Attempts to complete SSL handshake: 38
2023-01-20 01:53:30: SMTP (localhost:1587; 127.0.0.1:48532->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 02:08:30: SMTP (localhost:1587; 127.0.0.1:34566->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 02:10:03: SMTP (localhost:1587; 127.0.0.1:35384->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 02:13:30: SMTP (localhost:1587; 127.0.0.1:36992->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 02:13:30: SMTP (localhost:1587; 127.0.0.1:37004->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 02:23:30: SMTP (localhost:1587; 127.0.0.1:43740->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 02:28:30: SMTP (localhost:1587; 127.0.0.1:38600->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 02:28:30: SMTP (localhost:1587; 127.0.0.1:38610->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 02:28:30: SMTP (localhost:1587; 127.0.0.1:38614->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-20 02:38:30: SMTP (localhost:1587; 127.0.0.1:48916->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 02:38:30: SMTP (localhost:1587; 127.0.0.1:48928->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 02:38:30: SMTP (localhost:1587; 127.0.0.1:48914->smtp.office365.com:587) Attempts to complete SSL handshake: 50
2023-01-20 02:40:04: SMTP (localhost:1587; 127.0.0.1:44634->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 02:43:30: SMTP (localhost:1587; 127.0.0.1:48202->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 02:53:31: SMTP (localhost:1587; 127.0.0.1:42782->smtp.office365.com:587) Attempts to complete SSL handshake: 38
2023-01-20 02:58:30: SMTP (localhost:1587; 127.0.0.1:48196->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 02:58:30: SMTP (localhost:1587; 127.0.0.1:48210->smtp.office365.com:587) Attempts to complete SSL handshake: 48
2023-01-20 02:58:30: SMTP (localhost:1587; 127.0.0.1:48226->smtp.office365.com:587) Attempts to complete SSL handshake: 50
2023-01-20 03:08:30: SMTP (localhost:1587; 127.0.0.1:57864->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 03:08:30: SMTP (localhost:1587; 127.0.0.1:57846->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 03:08:30: SMTP (localhost:1587; 127.0.0.1:57860->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 03:08:30: SMTP (localhost:1587; 127.0.0.1:57880->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 03:10:03: SMTP (localhost:1587; 127.0.0.1:50338->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 03:18:30: SMTP (localhost:1587; 127.0.0.1:49734->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 03:18:30: SMTP (localhost:1587; 127.0.0.1:49744->smtp.office365.com:587) Attempts to complete SSL handshake: 48
2023-01-20 03:18:30: SMTP (localhost:1587; 127.0.0.1:49756->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 03:20:03: SMTP (localhost:1587; 127.0.0.1:56090->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 03:23:31: SMTP (localhost:1587; 127.0.0.1:37870->smtp.office365.com:587) Attempts to complete SSL handshake: 48
2023-01-20 03:38:30: SMTP (localhost:1587; 127.0.0.1:60048->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 03:38:30: SMTP (localhost:1587; 127.0.0.1:60046->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 03:40:04: SMTP (localhost:1587; 127.0.0.1:47874->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 03:43:30: SMTP (localhost:1587; 127.0.0.1:51266->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 03:50:04: SMTP (localhost:1587; 127.0.0.1:47252->smtp.office365.com:587) Attempts to complete SSL handshake: 46
2023-01-20 03:53:30: SMTP (localhost:1587; 127.0.0.1:48576->smtp.office365.com:587) Attempts to complete SSL handshake: 46
2023-01-20 03:53:30: SMTP (localhost:1587; 127.0.0.1:48568->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 03:53:30: SMTP (localhost:1587; 127.0.0.1:48584->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 04:03:31: SMTP (localhost:1587; 127.0.0.1:39560->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-20 04:08:30: SMTP (localhost:1587; 127.0.0.1:40118->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 04:08:30: SMTP (localhost:1587; 127.0.0.1:40122->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 04:10:03: SMTP (localhost:1587; 127.0.0.1:60620->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 04:18:30: SMTP (localhost:1587; 127.0.0.1:56158->smtp.office365.com:587) Attempts to complete SSL handshake: 38
2023-01-20 04:18:30: SMTP (localhost:1587; 127.0.0.1:56170->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 04:20:04: SMTP (localhost:1587; 127.0.0.1:54578->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 04:23:30: SMTP (localhost:1587; 127.0.0.1:60762->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 04:33:30: SMTP (localhost:1587; 127.0.0.1:54384->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 04:38:30: SMTP (localhost:1587; 127.0.0.1:53384->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 04:38:30: SMTP (localhost:1587; 127.0.0.1:53398->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 04:38:30: SMTP (localhost:1587; 127.0.0.1:53362->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 04:38:30: SMTP (localhost:1587; 127.0.0.1:53370->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 04:50:03: SMTP (localhost:1587; 127.0.0.1:42862->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 04:53:30: SMTP (localhost:1587; 127.0.0.1:56184->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-20 04:58:30: SMTP (localhost:1587; 127.0.0.1:41360->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 04:58:30: SMTP (localhost:1587; 127.0.0.1:41344->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 05:08:30: SMTP (localhost:1587; 127.0.0.1:36362->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 05:08:30: SMTP (localhost:1587; 127.0.0.1:36382->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 05:08:30: SMTP (localhost:1587; 127.0.0.1:36352->smtp.office365.com:587) Attempts to complete SSL handshake: 51
2023-01-20 05:08:30: SMTP (localhost:1587; 127.0.0.1:36370->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 05:08:30: SMTP (localhost:1587; 127.0.0.1:36358->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 05:18:30: SMTP (localhost:1587; 127.0.0.1:40474->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 05:18:30: SMTP (localhost:1587; 127.0.0.1:40486->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 05:18:30: SMTP (localhost:1587; 127.0.0.1:40470->smtp.office365.com:587) Attempts to complete SSL handshake: 46
2023-01-20 05:20:04: SMTP (localhost:1587; 127.0.0.1:39312->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 05:28:30: SMTP (localhost:1587; 127.0.0.1:56718->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 05:28:30: SMTP (localhost:1587; 127.0.0.1:56716->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 05:28:30: SMTP (localhost:1587; 127.0.0.1:56724->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 05:28:30: SMTP (localhost:1587; 127.0.0.1:56732->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 05:30:04: SMTP (localhost:1587; 127.0.0.1:52748->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 05:38:30: SMTP (localhost:1587; 127.0.0.1:52064->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 05:38:30: SMTP (localhost:1587; 127.0.0.1:52088->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 05:38:30: SMTP (localhost:1587; 127.0.0.1:52076->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 05:38:30: SMTP (localhost:1587; 127.0.0.1:52084->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 05:38:30: SMTP (localhost:1587; 127.0.0.1:52092->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 05:48:31: SMTP (localhost:1587; 127.0.0.1:44088->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 05:48:31: SMTP (localhost:1587; 127.0.0.1:44076->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 05:48:31: SMTP (localhost:1587; 127.0.0.1:44104->smtp.office365.com:587) Attempts to complete SSL handshake: 51
2023-01-20 05:50:03: SMTP (localhost:1587; 127.0.0.1:52890->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-20 05:53:30: SMTP (localhost:1587; 127.0.0.1:57210->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-20 06:00:04: SMTP (localhost:1587; 127.0.0.1:51934->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 06:03:31: SMTP (localhost:1587; 127.0.0.1:52966->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 06:08:30: SMTP (localhost:1587; 127.0.0.1:56902->smtp.office365.com:587) Attempts to complete SSL handshake: 46
2023-01-20 06:08:30: SMTP (localhost:1587; 127.0.0.1:56908->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 06:20:04: SMTP (localhost:1587; 127.0.0.1:54912->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-20 06:23:31: SMTP (localhost:1587; 127.0.0.1:32806->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 06:23:31: SMTP (localhost:1587; 127.0.0.1:32816->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 06:23:31: SMTP (localhost:1587; 127.0.0.1:32804->smtp.office365.com:587) Attempts to complete SSL handshake: 51
2023-01-20 06:23:31: SMTP (localhost:1587; 127.0.0.1:32788->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 06:38:30: SMTP (localhost:1587; 127.0.0.1:49490->smtp.office365.com:587) Attempts to complete SSL handshake: 38
2023-01-20 06:40:04: SMTP (localhost:1587; 127.0.0.1:34912->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-20 06:43:30: SMTP (localhost:1587; 127.0.0.1:44202->smtp.office365.com:587) Attempts to complete SSL handshake: 44
2023-01-20 06:43:30: SMTP (localhost:1587; 127.0.0.1:44204->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 06:43:30: SMTP (localhost:1587; 127.0.0.1:44198->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 06:53:30: SMTP (localhost:1587; 127.0.0.1:47964->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 06:53:30: SMTP (localhost:1587; 127.0.0.1:47990->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-20 06:53:30: SMTP (localhost:1587; 127.0.0.1:47976->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 06:53:30: SMTP (localhost:1587; 127.0.0.1:47994->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 06:53:30: SMTP (localhost:1587; 127.0.0.1:47998->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-20 07:03:30: SMTP (localhost:1587; 127.0.0.1:53752->smtp.office365.com:587) Attempts to complete SSL handshake: 48
2023-01-20 07:03:30: SMTP (localhost:1587; 127.0.0.1:53760->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 07:03:30: SMTP (localhost:1587; 127.0.0.1:53762->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 07:03:30: SMTP (localhost:1587; 127.0.0.1:53750->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 07:03:30: SMTP (localhost:1587; 127.0.0.1:53772->smtp.office365.com:587) Attempts to complete SSL handshake: 49
2023-01-20 07:18:30: SMTP (localhost:1587; 127.0.0.1:49754->smtp.office365.com:587) Attempts to complete SSL handshake: 48
2023-01-20 07:18:30: SMTP (localhost:1587; 127.0.0.1:49770->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 07:18:30: SMTP (localhost:1587; 127.0.0.1:49784->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-20 07:18:30: SMTP (localhost:1587; 127.0.0.1:49774->smtp.office365.com:587) Attempts to complete SSL handshake: 47
2023-01-20 07:20:03: SMTP (localhost:1587; 127.0.0.1:57246->smtp.office365.com:587) Attempts to complete SSL handshake: 42

Certainly seems better!

@simonrob
Copy link
Owner

That looks much better!

Please let me know if you encounter the issue again, but if not I'll merge this branch in the next week or so.

Thanks for the help in identifying and resolving this.

@simonrob
Copy link
Owner

0ef9f9e further improves this by using select with a timeout, rather than simply sleeping for 1ms. This should further reduce the number of handshake attempts required.

@brianjmurrell
Copy link
Contributor Author

0ef9f9e further improves this by using select with a timeout, rather than simply sleeping for 1ms. This should further reduce the number of handshake attempts required.

2023-01-23 09:18:45: SMTP (localhost:1587; 127.0.0.1:46884->smtp.office365.com:587) Attempts to complete SSL handshake: 5
2023-01-23 09:18:45: SMTP (localhost:1587; 127.0.0.1:46920->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:18:45: SMTP (localhost:1587; 127.0.0.1:46904->smtp.office365.com:587) Attempts to complete SSL handshake: 5
2023-01-23 09:18:45: SMTP (localhost:1587; 127.0.0.1:46900->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:28:45: SMTP (localhost:1587; 127.0.0.1:57916->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:28:45: SMTP (localhost:1587; 127.0.0.1:57930->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:28:45: SMTP (localhost:1587; 127.0.0.1:57922->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:28:45: SMTP (localhost:1587; 127.0.0.1:57944->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:28:45: SMTP (localhost:1587; 127.0.0.1:57948->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:35:42: SMTP (localhost:1587; 127.0.0.1:40978->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:13: SMTP (localhost:1587; 127.0.0.1:59136->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:13: SMTP (localhost:1587; 127.0.0.1:59154->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:14: SMTP (localhost:1587; 127.0.0.1:59140->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:14: SMTP (localhost:1587; 127.0.0.1:59170->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-23 09:36:14: SMTP (localhost:1587; 127.0.0.1:59176->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:14: SMTP (localhost:1587; 127.0.0.1:59190->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:15: SMTP (localhost:1587; 127.0.0.1:59204->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:15: SMTP (localhost:1587; 127.0.0.1:59180->smtp.office365.com:587) Attempts to complete SSL handshake: 43
2023-01-23 09:36:16: SMTP (localhost:1587; 127.0.0.1:59202->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:16: SMTP (localhost:1587; 127.0.0.1:59236->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:17: SMTP (localhost:1587; 127.0.0.1:59248->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:17: SMTP (localhost:1587; 127.0.0.1:59272->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:17: SMTP (localhost:1587; 127.0.0.1:59220->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:17: SMTP (localhost:1587; 127.0.0.1:59288->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:17: SMTP (localhost:1587; 127.0.0.1:59310->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:17: SMTP (localhost:1587; 127.0.0.1:59232->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:17: SMTP (localhost:1587; 127.0.0.1:59240->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-23 09:36:17: SMTP (localhost:1587; 127.0.0.1:59242->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:18: SMTP (localhost:1587; 127.0.0.1:43506->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:18: SMTP (localhost:1587; 127.0.0.1:59254->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-23 09:36:18: SMTP (localhost:1587; 127.0.0.1:59258->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:18: SMTP (localhost:1587; 127.0.0.1:59280->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:18: SMTP (localhost:1587; 127.0.0.1:59314->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:18: SMTP (localhost:1587; 127.0.0.1:59298->smtp.office365.com:587) Attempts to complete SSL handshake: 45
2023-01-23 09:36:19: SMTP (localhost:1587; 127.0.0.1:43504->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:52: SMTP (localhost:1587; 127.0.0.1:52456->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-23 09:36:52: SMTP (localhost:1587; 127.0.0.1:52482->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-23 09:36:52: SMTP (localhost:1587; 127.0.0.1:52450->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:52: SMTP (localhost:1587; 127.0.0.1:52438->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:52: SMTP (localhost:1587; 127.0.0.1:52470->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:54: SMTP (localhost:1587; 127.0.0.1:52490->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:54: SMTP (localhost:1587; 127.0.0.1:52532->smtp.office365.com:587) Attempts to complete SSL handshake: 5
2023-01-23 09:36:54: SMTP (localhost:1587; 127.0.0.1:52548->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:54: SMTP (localhost:1587; 127.0.0.1:52562->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:55: SMTP (localhost:1587; 127.0.0.1:52586->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:55: SMTP (localhost:1587; 127.0.0.1:52584->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:55: SMTP (localhost:1587; 127.0.0.1:52520->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:56: SMTP (localhost:1587; 127.0.0.1:52500->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-23 09:36:56: SMTP (localhost:1587; 127.0.0.1:52570->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:56: SMTP (localhost:1587; 127.0.0.1:52504->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:56: SMTP (localhost:1587; 127.0.0.1:52616->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:56: SMTP (localhost:1587; 127.0.0.1:52636->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:56: SMTP (localhost:1587; 127.0.0.1:52638->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:56: SMTP (localhost:1587; 127.0.0.1:52646->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:56: SMTP (localhost:1587; 127.0.0.1:52678->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:36:57: SMTP (localhost:1587; 127.0.0.1:52604->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-23 09:36:57: SMTP (localhost:1587; 127.0.0.1:52606->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:57: SMTP (localhost:1587; 127.0.0.1:52624->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:57: SMTP (localhost:1587; 127.0.0.1:52662->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:36:57: SMTP (localhost:1587; 127.0.0.1:52666->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-23 09:37:10: SMTP (localhost:1587; 127.0.0.1:54446->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:37:10: SMTP (localhost:1587; 127.0.0.1:54466->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:37:10: SMTP (localhost:1587; 127.0.0.1:54440->smtp.office365.com:587) Attempts to complete SSL handshake: 6
2023-01-23 09:37:11: SMTP (localhost:1587; 127.0.0.1:54450->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:37:12: SMTP (localhost:1587; 127.0.0.1:54482->smtp.office365.com:587) Attempts to complete SSL handshake: 88
2023-01-23 09:37:13: SMTP (localhost:1587; 127.0.0.1:54492->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-23 09:37:13: SMTP (localhost:1587; 127.0.0.1:54498->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:37:13: SMTP (localhost:1587; 127.0.0.1:54512->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-23 09:37:13: SMTP (localhost:1587; 127.0.0.1:54514->smtp.office365.com:587) Attempts to complete SSL handshake: 39
2023-01-23 09:37:13: SMTP (localhost:1587; 127.0.0.1:54528->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:37:13: SMTP (localhost:1587; 127.0.0.1:54516->smtp.office365.com:587) Attempts to complete SSL handshake: 42
2023-01-23 09:37:15: SMTP (localhost:1587; 127.0.0.1:54538->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:37:15: SMTP (localhost:1587; 127.0.0.1:54546->smtp.office365.com:587) Attempts to complete SSL handshake: 41
2023-01-23 09:37:16: SMTP (localhost:1587; 127.0.0.1:54554->smtp.office365.com:587) Attempts to complete SSL handshake: 40
2023-01-23 09:37:16: SMTP (localhost:1587; 127.0.0.1:54558->smtp.office365.com:587) Attempts to complete SSL handshake: 41

@simonrob
Copy link
Owner

This seems to be working well (and similarly in my own testing). I plan to merge this branch in the next week or so unless any issues arise.

simonrob added a commit that referenced this issue Feb 8, 2023
Fixes an issue with sending large attachments (SMTP), which was a regression in 4651993 (#121)
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

Successfully merging a pull request may close this issue.

3 participants