loopbackio/loopback-connector-postgresql

Error when using transaction timeout

Opened this issue · 6 comments

Steps to reproduce

loopback-connector-postgresql version is 5.3.0
node version is v14.1.0

await app.datasources.db.transaction(async myTxModels => {
    await customFunction(element, {
        db1: db1TxModels, 
        db2: db2Models
    }).catch(err => { throw err });

}, { timeout: 240000 });

Current Behavior

aftersome time, app crashes with the following error

tx.notifyObserversOf('timeout', context, function(err) {
           ^

TypeError: tx.notifyObserversOf is not a function
    at Timeout._onTimeout (\node_modules\loopback-connector\lib\transaction.js:124:12)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale commented

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

I'm experiencing this issue ! 😕 I'm in the process of upgrading a node project running with Node 10, bringing it to the latest version of Node (v14.17.3).

I have some behaviour tests (endpoint tests) to make sure that I didn't break anything. When I execute my tests, at random points (after at least 5 seconds, so many requests) my backend crashes with the following error:

TypeError: tx.notifyObserversOf is not a function
    at Timeout._onTimeout (/home/cluis/Projects/Exeboard/dev/exeboard-web-2/backend/node_modules/loopback-connector/lib/transaction.js:124:12)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)
[nodemon] app crashed - waiting for file changes before starting...

I have no idea what is happening because the error ocurrs at random places. Help, please !!!

    "loopback": "^3.28.0",
    "loopback-boot": "^3.3.1",
    "loopback-component-explorer": "^6.5.1",
    "loopback-connector-postgresql": "5.4.0",
    "loopback-console": "^1.1.0",

@cluis13915 @nicoskk I am facing the same issue, have you came across any solution for this?

@prachitin I just avoided setting the timeout option in Model.beginTransaction({ ...options }, callback) 😕

Since version 5.1.0 which updates its dependencies (loopback-connector: ^5.0.0) It will give this error with loopback 3.
The latest version of loopback 3 (3.28.0) depends on loopback-datasource-juggler which depends on loopback-connector: "^4.4.0"

The transaction is created with loopback-connector@5 for loopback-connector-postgresql, but loopback will use loopback-connector@4 which is modified by this line https://github.com/loopbackio/loopback-datasource-juggler/blob/3.x/lib/transaction.js#L117

The solution I found was to install loopback-connector as a direct dependency
npm install loopback-connector@5
This makes all packages use the same version of the package with the ObserverMixin applied to it