Skip to content

Large / slow transaction terminates process without throwing exception #658

@mschneider

Description

@mschneider

I don't have a minimal reproduction yet, but I wanted to report this issue anyways.

Basically what I'm trying to do is insert 100,000 of entries into a database as a transaction with rollback in case I have a data mapping issue in between.

My code is roughly:

console.log("tx begin");
await sql.begin("READ WRITE", async (tsql) => {
    await Promise.all([...].map(async (x) => { 
         console.log("insert begin");
         await tsql`insert into table ${x}`;
         console.log("insert end");
    }));
    console.log("tx end"
 });
console.log("await end");

The output I get is:

tx begin
insert begin
insert end
...
insert begin
✨  Done in 102.00s.

I started looking a bit inside the begin implementation, inside scope, this promise never resolves or rejects.

 result = await new Promise((resolve, reject) => {
          const x = fn(sql)
          Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(resolve, reject)
        })

On my postgres server I get the following error in the log:

[info] postgres | 2023-08-10 00:36:57.064 UTC [14596] LOG: unexpected EOF on client connection with an open transaction

The interesting part here is that the promise seemingly just stops executing and then the process exits. I wonder if this is a load balancing issue on my postgres server, will need to investigate more. In any case I would expect at least a client side error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions