aboutsummaryrefslogtreecommitdiff
path: root/deliver_local.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-01-15 20:17:36 +0800
committerRunxi Yu <me@runxiyu.org>2025-01-15 20:17:36 +0800
commit71d2d56cd4b4112b33b73322d1680dd965113018 (patch)
treebc40e0de74af7e1b79e92af40f09e77f329a6de5 /deliver_local.go
parentPut mx side parsing code into a block (diff)
downloadmaild-71d2d56cd4b4112b33b73322d1680dd965113018.tar.gz
maild-71d2d56cd4b4112b33b73322d1680dd965113018.tar.zst
maild-71d2d56cd4b4112b33b73322d1680dd965113018.zip
Minor fixes
Diffstat (limited to 'deliver_local.go')
-rw-r--r--deliver_local.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/deliver_local.go b/deliver_local.go
index 47af7f9..7e98aa6 100644
--- a/deliver_local.go
+++ b/deliver_local.go
@@ -2,16 +2,24 @@ package main
import (
"context"
+ "errors"
+ "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)
-func deliver_local(ctx context.Context, db *pgxpool.Pool, envelope_from string, envelope_recipients []string, data []byte, addresses []string) error {
+func deliver_local(ctx context.Context, db *pgxpool.Pool, envelope_from string, envelope_recipients []string, data []byte, addresses []string) (err error) {
tx, err := db.Begin(ctx)
if err != nil {
return err
}
- defer tx.Rollback(ctx) // BUG: Potential missed error here, but this will always fail if commit succeeded
+ defer func() {
+ err = tx.Rollback(ctx)
+ if errors.Is(err, pgx.ErrTxClosed) {
+ err = nil
+ return
+ }
+ }()
for _, address := range addresses {
_, err = tx.Exec(ctx, "INSERT INTO mail (mailbox_id, data) SELECT a.mailbox_id, $2::bytea FROM addresses a JOIN mailboxes m ON a.mailbox_id = m.id WHERE a.address = $1;", address, data)
if err != nil {