Skip to content

database is locked error when using reroute #786

Open

Description

@balejk

Describe the bug

I am trying to implement a simple mailing-list-like functionality using maddy only. I have added a corresponding configuration block so that recipients of emails addressed to a specified address get rewritten according to an aliases file and delivered either locally or injected to the remote queue. However when I send an email to both the mailing list address and some other address on the server, the IMAP database seems to get deadlocked with the email failing to deliver and breaking the delivery of any further emails until the restart of maddy.

Steps to reproduce

Modify the default configuration file as below and send an email addressed to both mailing.list@example.org and postmaster@example.org.

Log files

imapsql: readUids (listMsgUidsRecent) []: database is locked   {"mbox":"INBOX","mboxId":1,"username":"postmaster@example.org","uid":1}
imapsql: GetMailbox [INBOX]: imapsql: serialization failure, try again later   {"username":"postmaster@example.org","uid":1}
smtp: DATA error        {"msg_id":"dc377837","reason":" GetMailbox INBOX: imapsql: serialization failure, try again later"}

Configuration file

I use the default configuration file with the following block added to the top of the default local_routing msgpipeline:

    destination mailing.list@example.org {
		modify {
			replace_rcpt file /etc/maddy/mailing-list
		}

		reroute {
			destination mailing.list@example.org {
				reject 550 5.1.1 "User doesn't exist"
			}

			destination postmaster $(local_domains) {
				deliver_to &local_routing
			}

			default_destination {
				deliver_to &remote_queue
			}
		}
	}

I also tried swapping the deliver_to &local_routing line above for deliver_to &local_mailboxes with the same outcome.

Note that the default destination postmaster $(local_domains) section is still present below the above to facilitate delivery to addresses different than the virtual mailing list.

Environment information

  • maddy version: 0.8.1 on glibc-based Void Linux

Activity

  1. balejk commented on Jul 6, 2025

    @balejk
    ContributorAuthor

    I have now encountered this error in another setup as well:

    msgpipeline local_routing {
        # Insert handling for special-purpose local domains here.
        # e.g.
        # destination lists.example.org {
        #     deliver_to lmtp tcp://127.0.0.1:8024
        # }
    
        destination list@example.org {
    	    deliver_to lmtp unix:///....sock
        }
    
        destination postmaster $(local_domains) {
            modify {
                replace_rcpt &local_rewrites
                replace_rcpt static {
                    entry bounces@example.org postmaster@example.org
                }
            }
    
            deliver_to &local_mailboxes
        }
    
        default_destination {
            reject 550 5.1.1 "User doesn't exist"
        }
    }
    

    At the lmtp socket listens a program which upon receiving a message immediately opens a submission connection to the same maddy and forwards the message to a predefined list of addresses (it's a simple mailing list service). It sends the messages as bounces@example.org which has only submission access and incoming messages are aliased to postmaster.

    The error occurs when a maddy account which is among the mailing list recipients sends a message to the mailing list and to self at once (i. e. To: user@example.org, list@example.org, From: user@example.org). It seems that maddy tries to deliver the original message which the user sent to self but at the same time the lmtp service opens another submission connection which also wants to deliver to this account which leads to the locked error.

    As in the previous case, the database remains locked until maddy restart, even though this transaction fails.

    Also, the problem doesn't seem to occur in this case if the sender is external, i. e. not an account on the same maddy instance (with the recipients being the same, i. e. the user and the mailing list which they subscribe to).

  2. link2xt commented on Mar 12, 2026

    @link2xt

    The issue possibly belongs to https://github.com/foxcpp/go-imap-sql

  3. foxcpp commented on Apr 12, 2026

    @foxcpp
    Owner

    Woops, accidentally closed this one.

  4. reopened this on Apr 12, 2026
  5. added a commit that references this issue on Apr 12, 2026
    2f6a4cf
  6. self-assigned this
    on Apr 12, 2026
  7. moved this from Triage to TODO in Maddy Mail Server Task Trackeron Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions