Opened 14 months ago

Last modified 14 months ago

#18579 new bug

General OS error while establishing a connection with iCloud SMTP

Reported by: Nexus-6 Owned by: axeld
Priority: normal Milestone: Unscheduled
Component: Servers/mail_daemon Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description (last modified by Nexus-6)

I already investigated this issue in the past to no avail, until yesterday. The symptom is that attempting to connect to smtp.mail.me.com results in a connection error. More specifically, iCloud SMTP should be listening to port 587 (TLS). Either configuring in the Outgoing panel smtp.mail.me.com with SSL or smtp.mail.me.com:587 alway result in a cryptic General OS error showed by the mail daemon log windows. Digging in the SMTP outbound SMTP addon, the problem seems to be in the call to status_t SMTPProtocol::Open(const char *address, int port, bool esmtp) and more specifically in fSocket->Connect(addr).

I have reproduced the code above in an isolated simple console application and the result is the same, unless at some point by trying all sorts of combinations of ports, it connected and trying to send an email worked! Until I rebooted. This time I had to do some additional voodoo, after succesfully trying to connect with this small test app I had to restart the mail_demon. The voodoo, although I'm not certain of what the sequence exactly is and what triggers this behaviour, consists of a ping to the address of the smtp server and an attempt to connect via terminal with openssl s_client -connect smtp.mail.me.com:587 -crlf or openssl s_client -connect smtp.mail.me.com:587 -crlf

I should add that neither openssl consistently connects. No other SMTP server I have tried has this issue, but I have not tried a single one with the triple dot in the hostname. It maight sound silly but this is the only difference I can see, considering we barely are the transport layer.

Note: hrev 57257

Attachments (5)

syslog (256.7 KB ) - added by Nexus-6 14 months ago.
syslog.old (512.0 KB ) - added by Nexus-6 14 months ago.
Old syslog for comparison
App.cpp (2.0 KB ) - added by Nexus-6 14 months ago.
simple code to test connection to iCloud SMTP server
strace_log (40.0 KB ) - added by Nexus-6 14 months ago.
App.2.cpp (2.6 KB ) - added by Nexus-6 14 months ago.
new version of the code which strace is run against

Download all attachments as: .zip

Change History (17)

by Nexus-6, 14 months ago

Attachment: syslog added

by Nexus-6, 14 months ago

Attachment: syslog.old added

Old syslog for comparison

by Nexus-6, 14 months ago

Attachment: App.cpp added

simple code to test connection to iCloud SMTP server

comment:1 by Nexus-6, 14 months ago

A quick update: today there was no way to connect to the smtp server neither with my test app nor with Mail Kit. Openssl is the only one that worked just with port 587.

Then I modified my test code to force a connection without ssl before attempting a secure connection, that means using BSocket instead of BSecureSocket. Doing this, BSocket failed but the secure connection on port 465 was established and Mail Kit began to work again!

This is very weird, indeed.

comment:2 by Nexus-6, 14 months ago

Description: modified (diff)

comment:3 by nephele, 14 months ago

Component: Network & Internet/StackServers/mail_daemon
Keywords: smtp icloud socket general OS error removed

Please don't add random keywords :)

comment:4 by waddlesplash, 14 months ago

Please record an strace (make sure to specify the flag to trace all threads) to see what's happening, and upload the log here.

in reply to:  3 comment:5 by Nexus-6, 14 months ago

Replying to nephele:

Please don't add random keywords :)

You might not agree with my selection but rest assured they were all but random. And more importantly, this issue is not with the mail daemon but with the network stack as demonstrated by my tests. May I suggest reverting back to the previous one?

by Nexus-6, 14 months ago

Attachment: strace_log added

by Nexus-6, 14 months ago

Attachment: App.2.cpp added

new version of the code which strace is run against

comment:6 by waddlesplash, 14 months ago

[  6334] connect(0x4, {AF_INET, 17.57.156.26/465}, 0x20) = 0x80007020 Connection refused (114654 us)

comment:7 by Nexus-6, 14 months ago

This is not a surprise, maybe there’s a problem with the way BSecureSocket tries to establish a connection that iCloud doesn’t like most of the times. For the records, other clients (including Beam) connect without any issue.

comment:8 by waddlesplash, 14 months ago

The socket options might provide a clue. A strace for comparison may help.

comment:9 by nephele, 14 months ago

Tags are ment for developers to organize tickets a bit more, if you add keywords like "error" that is noise making this harder. Unless you know some developer wants a certain tag or you need those yourself for your tickets please refrain from adding them.

in reply to:  8 comment:10 by Nexus-6, 14 months ago

Replying to waddlesplash:

The socket options might provide a clue. A strace for comparison may help.

I wasn’t able to set custom socket options via BSecureSocket unless I missed something obvious? I’ve tried instead to bypass it and establish the connection via socket(), setsockopts() and connect() but whatever option I set I can’t connect. socket() returns a bad file descriptor so I must be doing something wrong.

comment:11 by waddlesplash, 14 months ago

If socket() returns a bad FD, you should be able to check errno (or just look at strace) to see what went wrong.

At this point you will likely need to use packet capture to determine why the remote server rejected the connection request.

comment:12 by waddlesplash, 14 months ago

Also, error propagation in Mail should be fixed so it displays the proper "Connection refused" instead of "OS error".

Note: See TracTickets for help on using tickets.