The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
fix(mail-ingest): never queue a mail again for a failure after its commit
Maurice4cef885e12b4
diff --git a/server/src/nest/mail-ingest/mail-ingest-process.service.ts b/server/src/nest/mail-ingest/mail-ingest-process.service.tsindex 54dafd1fe..88b49c03b 100644--- a/server/src/nest/mail-ingest/mail-ingest-process.service.ts+++ b/server/src/nest/mail-ingest/mail-ingest-process.service.ts@@ -142,7 +142,7 @@ export class MailIngestProcessService {}if (kind.kind === 'forwarding_confirmation') {await this.keepForInbox(message, { ...outcome, forwardingCode: kind.code }, 'forwarding_confirmation', now);- await this.notify.bookingsPending(person.id, await this.candidates.countPending(person.id));+ await this.afterRead(message.id, () => this.pendingNotice(person.id));return;}await this.readBookings(message, raw, mail, person, outcome, now);@@ -171,7 +171,7 @@ export class MailIngestProcessService {return;}await this.keepForInbox(message, done, read.emptyReason, now);- await this.notify.bookingsPending(person.id, await this.candidates.countPending(person.id));+ await this.afterRead(message.id, () => this.pendingNotice(person.id));return;}const context: CheckContext = {@@ -184,7 +184,20 @@ export class MailIngestProcessService {};const planned = await this.plan(read.drafts, context, person, prefs);const added = await this.write(message, planned, done, now);- await this.afterCommit(added, planned, mail, person);+ await this.afterRead(message.id, () => this.afterCommit(added, planned, mail, person));+ }++ /** What follows a mail's commit fails on its own: the mail is read, so it is never queued again for it. */+ private async afterRead(messageId: number, step: () => Promise<void>): Promise<void> {+ try {+ await step();+ } catch (err) {+ logError(`[mail-ingest] After reading mail ${messageId}: ${err instanceof Error ? err.message : String(err)}`);+ }+ }++ private async pendingNotice(userId: number): Promise<void> {+ await this.notify.bookingsPending(userId, await this.candidates.countPending(userId));}/** The trips a booking of this mail may go to: the address's trip alone, or the person's editable ones. */@@ -376,7 +389,7 @@ export class MailIngestProcessService {});}, Promise.resolve());if (planned.some((booking) => booking.resolution === 'pending' && booking.prepared === null)) {- await this.notify.bookingsPending(person.id, await this.candidates.countPending(person.id));+ await this.pendingNotice(person.id);}}diff --git a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.tsindex 98f0dd08e..2ba1a5e02 100644--- a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts+++ b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts@@ -602,6 +602,23 @@ describe('what a mail names', () => {});describe('a mail that keeps failing', () => {+ it('is not read again when what follows its commit fails', async () => {+ const user = await person();+ const trip = await makeTrip(orm(), user.id, { start_date: '2030-03-01', end_date: '2030-03-10' });+ const announce = vi+ .spyOn(t.get(MailIngestApplyService), 'announce')+ .mockRejectedValueOnce(new Error('connection lost'));+ try {+ const messageId = await forward(user.id, eml('flight'));+ expect(await findRow(orm(), MailIngestMessages, { id: messageId })).toMatchObject({ status: 'processed' });+ expect(await job().tick(new Date(NOW.getTime() + 60 * 60 * 1000))).toBe(0);+ expect(await entriesOf(messageId)).toHaveLength(1);+ expect(await countRows(orm(), Reservations, { trip: trip.id })).toBe(1);+ } finally {+ announce.mockRestore();+ }+ });+it('is tried again later and given up after its last try', async () => {const user = await person();await makeTrip(orm(), user.id, { start_date: '2030-03-01', end_date: '2030-03-10' });