Skip to content

Don't try to send NOOP on conections that are most likely dead #69

Open

Description

@attilakinali

Hi,

In case sylpheed has been sitting idle for some time, it will try to send a NOOP to see whether the connection is still alive. But today, when most firewalls cut idle connections after 5-10 minutes, this means that sylpheed will inevitably have to wait for the connection timeout before it can continue.

There are two ways around this:

  1. Decrease the connection timeout. But this conflicts with any operation that might take some time on the server side, thus creating spurious timeouts and reconnects.

  2. Ignore any existing connection, if it has been idle for a long time and immediately reconnect. This of course requires to know when an idle connection might be dead. There are a few rules of thumb, but nothing hard and it changes depending on the network setup. Too short a time and we reconnect when we don't have to. Too long and we still run into the above problem of having to wait for the connection timeout.

I personally am of the opinion, that 2) is the better option and the price of having to reconnect when it isn't needed is comparatively small. I did a quick and dirty test like this:

--- ibsylph/imap.c
+++ libsylph/imap.c
@@ -558,7 +558,13 @@ static IMAPSession *imap_session_get(Fol
 		return IMAP_SESSION(rfolder->session);
 	}
 
-	if ((ret = imap_cmd_noop(IMAP_SESSION(rfolder->session))) != IMAP_SUCCESS) {
+	// ensure ret has a defined value
+	ret = 0;
+
+	// if the connection has been idle for more than 15 minutes
+	// or a NOOP command does not succeed: reconnect
+	if ( (time(NULL) - rfolder->session->last_access_time) > 60*15 
+			||(ret = imap_cmd_noop(IMAP_SESSION(rfolder->session))) != IMAP_SUCCESS) {
 		if (ret == IMAP_EAGAIN) {
 			g_warning("imap_session_get: session is busy.");
 			return NULL;

Of course, the 15minutes is arbitrary and just a quick hack. It probably should be a config option. But this solves for me the biggest problem that I have with my daily use of sylpheed.

Activity

  1. jodo13 commented on Jan 31, 2026

    @jodo13

    On point 2 I would like to add up something.

    Seamonkey mail client does this, ignore the current connection and create a new one by login-in again, at least the version I have here, and, do you know what happens with AOL/YAHOO?

    That they end blocking you with too many logins just for the single action of change one folder to another, of the same account, on an IMAP [theoretical persistent connection] a few times in a short period.

    And this might happen with other mail services as well.

    I think it is something to consider.

  2. attilakinali commented on Feb 2, 2026

    @attilakinali
    Author

    Opening too many connections isn't an issue here.

    1. The call to imap_session_reconnect() closes the connection before opening a new one, keeping the connection count constant.
    2. If the firewall forgot about the open connection and blocks the FIN packet, then there is no way we could gracefully close the connection anyways. I.e. nothing changes compared to the current behaviour. But in this case, the imap server should already have already dropped the connection due to a server side timeout.
    3. In case the firewall forgot the open connection but the server didn't timeout already, we will indeed open a new connection. But in this case, with a 15min idle-timeout we will open at most 2 connections per 30min of connection timeout demanded by the IMAP standard for IDLE connections. Which should be low enough so that no ban should be triggered.
    4. Open connections will not be ignored. The reconnect happens only if the connection has been idle for 15 minutes. Otherwise the connection is reused as normal.

    One thing to note here is that Seamonkey was (is?) known to open a connection for each open folder, which causes an excessive number of connections. This is far from what could happen with this kind of fix.

  3. jodo13 commented on Feb 2, 2026

    @jodo13

    As far as I remember, the problem, the error shown, is not the number of connections, well, yes, but not in that meaning, but the number of logins.

    I don't remember the exact wording, but was about logins, and sorry if I'm not going to test to avoid risks on my account (they are too bold with security lately).

    At some point Yahoo/AOL*** block for some time by the number of logins in a short period.

    Now, if it is because Seamonkey leaves open the connections and don't close them, I didn't test that.

    Anyway, I'm not developer, I'm just mentioning what could happen.

    By the way I remember suggesting something about the timeout issue on the mailing list years ago, you are not alone anyway, so, I'm not against it or anything else, but I fear that this fix could be worst than the actual behaviour.

    While is opt-out option, as for Yahoo/AOL cases, I don't care if someday is implemented.

    If I would go for an alternate option, I would go for send the NOOP command at intervals. As FTP protocol clients do for themselves, until the server simply closes the connection by a long connection.

    This way won't be a dumb timeout/waiting for the server readiness.

    Again, I'm not a developer, I just comment and suggest.

  4. attilakinali commented on Feb 4, 2026

    @attilakinali
    Author

    Yes, sending a periodic NOOP would be better. But I am not familiar enough with the code to know how to insert this. I am not even sure whether the current architecture allows this. Meanwhile, this is a single-line fix with no ill side effects (it will not trigger the too-many-login-attempts problem you mentioned). The only down side is that it's a bit clunky.

    And this is also the reason why this is a bug report not a pull-request. I am not confident that this is the right way to do things. The patch is only a suggestion of one way how to solve it.

  5. ldarby2 commented on Feb 4, 2026

    @ldarby2

    Periodic NOOPs was already done for pop, see rpop3_idle in src/rpop3.c - so it should be possible for imap by inserting something like this somewhere:

    static guint noop_timer = 0;
    noop_timer = g_timeout_add_full(G_PRIORITY_LOW, interval_in_milliseconds, imap_cmd_noop, session, NULL);
    

    Also I thought this was already solved by having a reduced timeout only for the noop command, which might also work, but apparently not - I went looking for that and found rpop3_idle instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions