Timo Sirainen [Thu, 23 Mar 2023 23:45:34 +0000 (01:45 +0200)]
imap: Improve disconnection log message if it happens immediately after unhibernation
The "No commands sent after unhibernation" can mean that imap-hibernate
process saw a timeout while unhibernating and shutdown the connection.
Or it can also mean just that the client itself disconnected.
Timo Sirainen [Thu, 23 Mar 2023 23:41:37 +0000 (01:41 +0200)]
imap-hibernate: If unhibernation fails, make sure imap process won't finish it later on
Especially if unhibernation fails due to a connection timeout to imap
process due to high load, it's possible that the imap process will
eventually finish the unhibernation and continue with the client. This is
rather confusing, since imap-hibernate process already logged that the
client got disconnected.
Timo Sirainen [Thu, 23 Mar 2023 20:23:39 +0000 (22:23 +0200)]
master: Fix service { idle_kill } to work better on busy servers
The previous behavior was to kill a process once it had idled for idle_kill
seconds. However, on a busy server the new connections are picked up somewhat
randomly by all the idling processes, so there's never any single process
idling for a long time. This effectively prevents the idle_kill from killing
any processes, even if there are unnecessarily many of them.
The new behavior here tracks the lowest number of idling processes during
idle_kill time interval. Then it kills that many processes. If the load
stays the same, this should shrink the number of processes to the number
that is needed to handle the load, but no more.
Timo Sirainen [Mon, 3 Apr 2023 21:43:55 +0000 (00:43 +0300)]
dsync: Fix handling mailboxes with % character when BROKENCHAR isn't explicitly set in config
When vname_escape_char (= BROKENCHAR) isn't explicitly set in configuration,
'%' character (or if it was hierarchy separator, '~') was used as the default
internal escape character. However, this was used inconsistently between local
and remote mailbox trees. The remote tree stored the mailbox names unescaped,
while the local mailbox names were escaped. This inconsistency caused dsync
to do unnecessary mailbox renames, which might have ended up failing.
This especially fixes dsync failures when mailbox name ended with the '%'
character.
Timo Sirainen [Thu, 9 Feb 2023 15:04:22 +0000 (17:04 +0200)]
lib-imap-client: Fix/clarify selection state handling
The old code assumed that selected_box would be non-NULL while a new mailbox
is being selected. That's not true though, the imapc-storage code closes the
old mailbox before selecting the next one. So the QRESYNC-specific code for
tracking selected-state was never being used. Fixed this, and clarified in
general how the selected-state is supposed to work.
Timo Sirainen [Thu, 9 Feb 2023 14:12:35 +0000 (16:12 +0200)]
imapc: Don't process untagged replies in mailbox that isn't fully selected yet
For example if the communication was:
C: a SELECT box1
...
C: b SELECT box2
S: * 1 EXPUNGE
S: * 1 EXISTS
S: * OK [UIDVALIDITY 1675948459] UIDs valid
S: ...
S: b OK
The expunge was intended for box1, not box2. This caused:
Warning: imapc(...): Mailbox '...' state corrupted: EXPUNGE received for empty mailbox - reconnecting
Fixed this by ignoring untagged EXPUNGE, FETCH, SEARCH and ESEARCH replies
when the UIDVALIDITY reply hasn't been yet received for a mailbox.
Markus Valentin [Mon, 9 Jan 2023 14:06:54 +0000 (15:06 +0100)]
welcome-plugin: Move script_execute() to welcome_create_box()
The welcome script was executed while opening the INBOX only when
the same session had created it. This could have led to unexpectedly not
executing welcome when not opening the mailbox right after it was created.
The original code delayed the welcome script run because mailbox creation
wasn't finished until the mailbox was opened. This seems to have become
fixed at some point.
Timo Sirainen [Mon, 26 Dec 2022 21:48:27 +0000 (23:48 +0200)]
lib-storage: Fix unnecessary data stack growth when iterating mailboxes
When listing mailbox list indexes, it was possible that each iteration
increased the data stack memory usage. It was all freed at the end though,
so this didn't cause any permanent leaks.
This change also slightly changes the lmtp log prefixes in some places.
It removes "conn $ip:$port [$idx]: rcpt $user:" from some of the log
messages (but that wasn't in all of the log messages anyway), but it now
always includes mail_log_prefix in these log messages, which previously
wasn't always set at that point yet.
Timo Sirainen [Tue, 25 Oct 2022 10:27:23 +0000 (13:27 +0300)]
replicator: Make sure to prevent request starvation
This synchronizes how priority queue is ordered vs what
replicator_queue_want_sync_now() returns. The mismatch might have caused
request starvation in some situations because they behaved differently.
Also this change makes sure that higher priority requests don't infinitely
block lower priority requests. Instead, they get a temporary boost time
(hardcoded 15-45 minutes). Afterwards lower priority requests are started
to be handled as well.
Timo Sirainen [Tue, 25 Oct 2022 10:11:37 +0000 (13:11 +0300)]
replicator: Don't update user's last_update if priority doesn't change
This didn't actually matter, since it was only used to check if importing
should update an existing user. However, importing is only run at startup
when all users have last_update=0 anyway.
The following changes bring new use cases for last_update.
Timo Sirainen [Tue, 25 Oct 2022 09:49:03 +0000 (12:49 +0300)]
replicator: Fix user placement in replication queue
Especially replicator queue importing and NOTIFY command could have
placed the user to wrong place in the queue, because they modified the
last sync timestamps afterwards.
Fixed by splitting replicator_queue_add() into get/update/add(), so all
the necessary changes can be done before replicator_queue_add() is used
to place the user into the queue.
Timo Sirainen [Thu, 27 Oct 2022 21:56:29 +0000 (00:56 +0300)]
maildir: If mailbox create fails, don't try to apply mailbox_update changes
This was especially causing problems with mailbox GUID mismatches in dsync.
The mismatch wasn't automatically fixed, because mailbox_create() incorrectly
kept updating the mailbox GUID for the already existing mailbox.
Fixes errors such as:
Remote lost mailbox GUID ... (maybe it was just deleted?)
Markus Valentin [Thu, 3 Mar 2022 13:21:00 +0000 (14:21 +0100)]
imapc: imapc_connection_disconnect_full() - Only conditionally abort
Only abort commands if there are no reconnect commands. Otherwise these
still will be handled and the commands memory will be freed after handling
them.
If the imapc connection was already disconnected when calling
imapc_connection_disconnect() it didn't clean up the commands and
especially the command pools.
Aki Tuomi [Wed, 21 Sep 2022 08:14:40 +0000 (11:14 +0300)]
lib-storage: LAYOUT=index rebuild - Fix rebuilds when using multiple namespaces
The old code did not properly populate the mailbox list for each
namespace, but only for the first namespace. This caused mailbox
storage existence checks to always fail.
Timo Sirainen [Tue, 11 Oct 2022 08:17:11 +0000 (11:17 +0300)]
lib-storage: Store mailbox names unescaped in box-name header
This header is used when rebuilding mailbox list indexes with LAYOUT=index.
The escape character is currently hardcoded for LAYOUT=index, so this
couldn't have broken anything unless the hardcoded separator was changed.
Still, this was wrong/confusing behavior.