Ambiguous error message "Connection closed by peer" when connecting to a TLS port with a non-TLS setting #788

Open
opened 2026-10-05 04:44:22 +02:00 by adam · 2 comments
Owner

A common mistake for the user is to connect to (for example) irc.freenode.net:6697 (note the lack of +).

ZNC fails connection with the error "Connection closed by peer", while not incorrect, it doesn't help the user figure out what's wrong.

A common mistake for the user is to connect to (for example) irc.freenode.net:6697 (note the lack of +). ZNC fails connection with the error "Connection closed by peer", while not incorrect, it doesn't help the user figure out what's wrong. <!-- github-sync-id:261906598 -->
Author
Owner

What do some clients produce in this case? How about openssl s_client or gnutls-cli?
I don't think there is anything that we can do in this case. TLS begins its handshake with the client sending something to the server. IRC begins with the client sending something to the server. A TLS server that gets USER instead of a valid TLS record will react by closing the connection. Thus, there is no more information available than "the other end closed the connection".

What do some clients produce in this case? How about `openssl s_client` or `gnutls-cli`? I don't think there is anything that we can do in this case. TLS begins its handshake with the client sending something to the server. IRC begins with the client sending something to the server. A TLS server that gets `USER` instead of a valid TLS record will react by closing the connection. Thus, there is no more information available than "the other end closed the connection". <!-- github-comment-id:333373410 -->
Author
Owner

For mIRC:

(16:36:12) * Connecting to chatfreenode.net (6697)
(16:36:13) * Disconnected

For WeeChat:

 irc: connecting to server chat.freenode.net/6697...
 irc: connected to chat.freenode.net/6697 (2001:1bc0:c1::6667)
 irc: reading data on socket: error 104 Connection reset by peer
 irc: disconnecting from server...
 irc: disconnected from server
 irc: reconnecting to server in 10 seconds

I guess they do more or less the same, but it's not uncommon for it to go wrong during troubleshooting.

One solution could be to enable SSL by default and the port 6697 as default as well, a "trying to speak securely to an unsecured socket" error is more obvious to catch and you don't run the risk of "forgetting to tick a ssl box"

As I mentioned on IRC the only alternative I saw was to getPort() == 6697 && ssl == false && error == Connection reset by peer

For mIRC: ``` (16:36:12) * Connecting to chatfreenode.net (6697) (16:36:13) * Disconnected ``` For WeeChat: ``` irc: connecting to server chat.freenode.net/6697... irc: connected to chat.freenode.net/6697 (2001:1bc0:c1::6667) irc: reading data on socket: error 104 Connection reset by peer irc: disconnecting from server... irc: disconnected from server irc: reconnecting to server in 10 seconds ``` I guess they do more or less the same, but it's not uncommon for it to go wrong during troubleshooting. One solution could be to enable SSL by default and the port 6697 as default as well, a "trying to speak securely to an unsecured socket" error is more obvious to catch and you don't run the risk of "forgetting to tick a ssl box" As I mentioned on IRC the only alternative I saw was to `getPort() == 6697 && ssl == false && error == Connection reset by peer` <!-- github-comment-id:333381120 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/znc#788