Billionmail/BillionMail · critical
Batch insert mailbox failed (batch %d-%d): %w
Error message
Batch insert mailbox failed (batch %d-%d): %w
What it means
Thrown inside the BatchAdd transaction when the batched InsertIgnore of mailboxes into the 'mailbox' table fails. The message includes the batch index range so you can tell which slice of the insert failed. Any insert error (constraint violation, connection loss, SQL syntax) aborts the whole transaction via the wrapped error returned from the closure.
Source
Thrown at core/internal/service/mail_boxes/mail_boxes.go:332
//if err != nil {
// return fmt.Errorf("Check the domain for a failure: %w", err)
//}
//if domainExists.IsEmpty() {
// return fmt.Errorf(" %s Not present or activated", domain)
//}
const batchSize = 100
for i := 0; i < len(mailboxes); i += batchSize {
end := i + batchSize
if end > len(mailboxes) {
end = len(mailboxes)
}
batch := mailboxes[i:end]
_, err := tx.Model("mailbox").Ctx(ctx).InsertIgnore(batch)
if err != nil {
return fmt.Errorf("Batch insert mailbox failed (batch %d-%d): %w", i, end-1, err)
}
for j := i; j < end; j++ {
createdEmails = append(createdEmails, emailList[j])
}
}
// If the limit is enabled, asynchronous will initialize the maildir and maildirsize for batch-created email accounts, and limit the concurrency
if quotaActive != 1 || quota <= 0 {
return nil
}
go func(mbs []v1.Mailbox) {
sem := make(chan struct{}, 10)
for i := range mbs {
mb := mbs[i]
sem <- struct{}{}View on GitHub (pinned to fc36c76c05)
Solutions
- Read the wrapped %w cause to see the exact SQL error
- Check for conflicting existing rows (duplicate username/local_part) in the mailbox table
- Verify database connectivity and connection-pool limits during large batch operations
- Reduce the batch size or count and retry the BatchAdd call
Defensive patterns
Strategy: retry
Validate before calling
// pre-check duplicates
for _, em := range emailList { if exists(em) { skip or rename } } Try / catch
if err != nil && strings.Contains(err.Error(), "Batch insert mailbox failed") {
// inspect wrapped SQL error, fix cause, retry batch
} Prevention
- Pre-check for duplicate usernames/local_parts before batch insert
- Ensure adequate DB connection pool size for large batches
- Keep batch sizes moderate and monitor DB health during bulk ops
When it happens
Trigger: BatchAddMailbox with a large count split into batches, where one tx.Model("mailbox").InsertIgnore(batch) fails — e.g. duplicate unique key not ignored by the DB, connection drop mid-transaction, or table schema mismatch.
Common situations: Postgres connection pool exhaustion under load; unique constraint conflicts on username/local_part when InsertIgnore semantics differ from expectations; oversized batch payloads.
Related errors
- Failed to create email: %w
- failed to import recipients (batch %d/%d): %w
- failed to insert alias: %v
- enqueue video job: %w
- failed to get all domains: %w
AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05).
Data as JSON: /api/errors/ea3af1472b3f24bf.
Report an issue: GitHub.