Closed Bug 2097852 Opened 5 days ago Closed 3 days ago

Sending emails via SSL/TLS stalls forever, fine with STARTTLS

Categories

(Core :: DOM: Networking, defect, P1)

Firefox 162
defect

Tracking

()

RESOLVED FIXED
163 Branch
Tracking Status
thunderbird_esr153 --- unaffected
firefox-esr115 --- unaffected
firefox-esr153 --- unaffected
firefox161 --- unaffected
firefox162 + affected
firefox163 + fixed

People

(Reporter: skyschub, Assigned: valentin, NeedInfo)

References

(Regression)

Details

(Keywords: regression, testcase)

Attachments

(3 files, 2 external files)

Attached file Networking log —

I have noticed that I can no longer send emails over SSL/TLS in Thunderbird beta, while everything is fine in Thunderbird 160 stable. Trying to send an email just results in the "Sending message..." dialog staying on screen forever, with no email actually being sent. Flipping to STARTTLS on another port seems to resolve this issue. Other clients on the same machine have no issue, and can send emails via SSL/TLS on port 465 just fine.

Setting mailnews.smtp.loglevel=All only dumps two lines of logs into the console:

mailnews.smtp: New SmtpClient instance created SmtpClient.sys.mjs:137:17
mailnews.smtp: Connecting to smtp://alpha.0b101010.email:465 SmtpClient.sys.mjs:172:19

I have attached a networking log with MOZ_LOG="timestamp,sync,nsHostResolver:5,GetAddrInfo:5,nsSocketTransport:5,negotiateauth:5" to this bug.

This seems to be a regression between 160 as I can never reproduce this on Release, but can break this all the time in Beta. mozregression gave me this regression range, although I have little confidence in that - it kinda feels wrong?

Attached image Wireshark screenshot —

Attached is now also a screenshot of a wireshark capture that I decrypted via the keys from SSLKEYLOGFILE.

You can see Thunderbird connecting, the mailserver responding with a greeting, and then... nothing until I eventually gave up on waiting after two minutes and ctrl-c'ed Thunderbird which closed the connection. I can share the raw capture privately if anyone wants to look at that, but I didn't see anything odd.

Summary: Can no longer send emails via TLS → Sending emails via SSL/TLS stalls forever, fine with STARTTLS
Component: General → Networking: SMTP
Product: Thunderbird → MailNews Core

Restarting doesn't help, correct?

Version: unspecified → Thunderbird 161

Correct, restarting both Thunderbird and the host OS - which I again forgot to mention: macOS 27.2.1 (26B131) - does not fix the issue. I can reproduce this every time in Thunderbird Beta.

It's also not a profile-specific issue, I can reproduce this in a freshly created profile.

I should also note that this isn't a generic networking issue: inbound mails via IMAP, moving mails around into different folders, all of that works. It's specifically sending that's broken, and also only with SSL/TLS, I have successfully sent several mails with STARTTLS in the last hour.

Hi all,

this is a very unfortunate regression caused by bug 2061626, which I filed to help us.

It is a race, only happening when the main thread is busy while the TLS handshake completes on the socket thread. TCPSocket then registers its handshake listener too late, HandshakeDone() is never called, and the socket stays in connecting forever without firing open, error or close.

I have a rather nasty, but reliable LLM conjured reproduction that passed before and fails now.

git apply bug2097852-tcpsocket-tls-open-race-test.diff
./mach xpcshell-test netwerk/test/unit/test_tcpsocket_tls_open_race.js

Needinfo to the people involved in the vicinity.

Thunderbird 162 cannot ship with this, a bug 2061626 and bug 2091547 backout may be the saner way than rushing to fix.

Thanks

Max

Severity: -- → S2
Component: Networking: SMTP → DOM: Networking
Flags: needinfo?(valentin.gosu)
Flags: needinfo?(rjesup)
Flags: needinfo?(jtracey)
Priority: -- → P1
Product: MailNews Core → Core
Regressed by: 2061626
See Also: → 2091547
Version: Thunderbird 161 → Firefox 162
Assignee: nobody → mozilla
Assignee: mozilla → nobody

Set release status flags based on info from the regressing bug 2061626

TCPSocket registers its handshake listener from the main thread once it
receives STATUS_CONNECTED_TO. If the handshake finishes on the socket thread
before that, the listener was never called and the socket stayed in the
connecting state forever.

Assignee: nobody → valentin.gosu
Status: NEW → ASSIGNED

Thunderbird 162 cannot ship with this, a bug 2061626 and bug 2091547 backout may be the saner way than rushing to fix.

I think Thunderbird is probably the only user of the TCPSocket API - so that's up to you, if you want to request a backout from beta.
Otherwise I'll focus on a fix to land on Nightly.

Flags: needinfo?(valentin.gosu)

Aside: It would probably be worthwhile to see if Thunderbird can use more of the Gecko network stack rather than having custom code.

I think the problem is that Gecko doesn't really need TCPSockets speaking random protocols like smtp. Moving the protocol implementations to Gecko is something I'd rather not do. And moving the dom TCPSocket to the thunderbird repo probably wouldn't work too well, since it's tied closely into our networking APIs, so it would break the build every time something changed.

Maybe what we need is the thunderbird tests running in CI for every push as a tier2?

STATUS_CONNECTED_TO is delivered asynchronously, so it can reach a socket that
was closed while connecting. A secure socket then registered a TLS handshake
listener after CloseHelper() cleared it, and the listener kept the socket alive.
A non-secure socket went back to open and fired an open event.

(In reply to Lars Eggert [:lars] from comment #10)

Aside: It would probably be worthwhile to see if Thunderbird can use more of the Gecko network stack rather than having custom code.

Yes and no, a shared Happy Eyeballs implementation for example is preferred, but Thunderbird speaking its own protocol implementations on top of TCP in C++, JS and potentially Rust is not going away anytime soon.

Thanks to everyone for the appropriately fast handling.

Pushed by valentin.gosu@gmail.com: https://github.com/mozilla-firefox/firefox/commit/98b5e2e70f28 https://hg.mozilla.org/integration/autoland/rev/d4e72bfd9a85 Notify a TLS handshake listener registered after the handshake has completed. r=necko-reviewers,kershaw,maxe https://github.com/mozilla-firefox/firefox/commit/9a710d614245 https://hg.mozilla.org/integration/autoland/rev/f4dfb01bf747 Ignore a TCPSocket connection status that arrives after close(). r=necko-reviewers,kershaw
Status: ASSIGNED → RESOLVED
Closed: 3 days ago
Resolution: --- → FIXED
Target Milestone: --- → 163 Branch

The patch landed in nightly and beta is affected.

:valentin, please make an uplift decision for beta:

  • For beta, nominate the patch for beta uplift approval if the fix should be included in this release, or set status-firefox162 to wontfix if the fix can wait for the next release.

The bugbug regressor model rates the riskiest of the 2 patches (d4e72bfd9a85) as medium risk: about 7% of the patches with this rating cause a regression. Given the severity of the bug, an uplift is recommended.

Uplift requests can be submitted from Lando: D346780, D346796.

See Requesting an Uplift for documentation on how to request an uplift.

For more information, please visit BugBot documentation.

Flags: needinfo?(valentin.gosu)

Yes, please uplift to beta

Duplicate of this bug: 2099387

@valentin Will you be putting in an uplift request for beta? If so they will need that soon as the final beta is Wed.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: