Skip to content

Commit 8d3851d

Browse files
committed
Eep, this bug has been present awhile.
The retry logic was not working because we were wrapping the error from pg (which had the code flag) before re-throwing.
1 parent 167731f commit 8d3851d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

server/src/pg.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ async function withExecutorAndPool<R>(
6363
console.log('Running query', sql, params);
6464
return await client.query(sql, params);
6565
} catch (e) {
66-
console.error('original error from pg', e);
67-
throw new Error(
68-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
69-
`Error executing SQL: ${sql}: ${(e as unknown as any).toString()}`,
70-
);
66+
console.error('Error executing SQL', e);
67+
throw e;
7168
}
7269
};
7370

@@ -122,7 +119,8 @@ async function transactWithExecutor<R>(
122119
throw new Error('Tried to execute transacation too many times. Giving up.');
123120
}
124121

125-
//stackoverflow.com/questions/60339223/node-js-transaction-coflicts-in-postgresql-optimistic-concurrency-control-and
122+
// Because we are using SERIALIZABLE isolation level, we need to be prepared to retry transactions.
123+
// stackoverflow.com/questions/60339223/node-js-transaction-coflicts-in-postgresql-optimistic-concurrency-control-and
126124
function shouldRetryTransaction(err: unknown) {
127125
// eslint-disable-next-line @typescript-eslint/no-explicit-any
128126
const code = typeof err === 'object' ? String((err as any).code) : null;

0 commit comments

Comments
 (0)