Open sawrubgupta opened 3 months ago
Are you using transactions anywhere? If you leave a client in an open transaction state without committing it or rolling it back before returning it to the pool, that transaction will never be committed, but other queries that happen to check out the same client will see its effects.
Hello, sorry for late reply, So wherever the API needs transaction I uses transaction and at other places I use simple pool.query So you are saying, whenever error occurs in error case I should use ROLLBACK ? This is my transaction API body
import pool from './db'
const client = await poo.connect();
try{
await client.query('BEGIN');
// all the client querty executes here
await client.query("COMMIT");
}catch(){
}finally{
client.release();
}
I think after client.release if there is no commit. rollback automatically happen right ? Please enlighten me, if I am doing anything wrong 🙏
Yeah definitely need a rollback there in catch. otherwise if there is an error your txn will be left open but the client will be released back to the pool
On Mon, Aug 5, 2024 at 7:38 AM sawrubgupta @.***> wrote:
Hello, sorry for late reply, So wherever the API needs transaction I uses transaction and at other places I use simple pool.query So you are saying, whenever error occurs in error case I should use ROLLBACK ? This is my transaction API body
import pool from './db' const client = await poo.connect(); try{ await client.query('BEGIN');
// all the client querty executes here
await client.query("COMMIT");
}catch(){
}finally{ client.release(); }
— Reply to this email directly, view it on GitHub https://github.com/brianc/node-postgres/issues/3286#issuecomment-2268865493, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMHINX37K2YDQDY4BWKB3ZP5P47AVCNFSM6AAAAABLWFUZNKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRYHA3DKNBZGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Yes, I added rollback everywhere in my code where i am using transaction, weird issues are coming up in code .
suppose sometime code is stuck at
const rows = await client.query(sql, val);
the code dont go below these lines, idk its issue with db or transsaction but I am using transaction in correct way.
Now this issue also comes sometimes
C:\Users\Saurabh\Desktop\prodninjamicroServceProd\extensionAndwebService\node_modules\pg\lib\client.js:132
const error = this._ending ? new Error('Connection terminated') : new Error('Connection terminated unexpectedly')
^
Error: Connection terminated unexpectedly
Guys please help, Its really scary, customer enters data but its not entering
Hello I have been using this library for more than 2 years but never faced this issue but in this few weeks I am facing a issue problem
I am using database pooling
this is my configuration
Now issue is I hit a create record api and then hit list record api, everything work perfectly fine till now but after some seconds, my newly inserted record disappears automatically.
No delete query is running sometimes it work and sometimes it doesnt.
List of whatplugin api
Now after hitting createWhatPlugin we hit whatPluginList api, and data comes in list api but after sometimes data automatically disappear.
I believe maybe its library issue ? can you please let me know 🙏