stacks-blockchain-api icon indicating copy to clipboard operation
stacks-blockchain-api copied to clipboard

API crashes on unexpected PG connection termination

Open CharlieC3 opened this issue 3 years ago • 0 comments

Describe the bug The API will crash when its connection to a PG database is unexpectedly terminated.

Shutting down... received uncaughtException.
Error processing core node block message Connection terminated unexpectedly
Error: Connection terminated unexpectedly
    at Connection.<anonymous> (/app/node_modules/pg/lib/client.js:132:73)
    at Object.onceWrapper (node:events:645:28)
    at Connection.emit (node:events:526:28)
    at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:107:12)
    at Socket.emit (node:events:538:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

API version: 3.0.2

To Reproduce Steps to reproduce the behavior:

  1. Start an API/stacks-node/PG database.
  2. Forcefully kill a PG connection by either force-killing the PG database, or force-killing a connection directly in the DB.
# Get PID
SELECT
  pid
FROM
  pg_stat_activity;

# Kill process
SELECT pg_terminate_backend(<PID>)

Expected behavior The API shouldn't crash, but rather gracefully handle the connection loss by attempting to re-establish a connection.

CharlieC3 avatar Apr 01 '22 17:04 CharlieC3