node-firebird icon indicating copy to clipboard operation
node-firebird copied to clipboard

Cannot set property 'lazy_count' of undefined

Open rscholant opened this issue 3 years ago • 15 comments

Cannot set property 'lazy_count' of undefined

After performing some operations on the database, this error is occurring and the application is finishing running. The strangest thing is that this error happens sporadically, there is no way to predict it.

Possible solution

After some tests, it was observed that in the line shown below, a value is being assigned to the lazy_count property in which it is undefined.

index.js - Line 3036

if (err) {
    xdr.buffer = xdr.buffer.slice(pos);
    xdr.pos = 0;
    self._xdr = xdr;

    if (self.accept.protocolMinimumType === ptype_lazy_send && self._queue.length > 0) {
        self._queue[0].lazy_count = 2; //THIS LINE IS THE PROBLEM
    }
    return;
}

With this change the error no longer occurs, but the return of the query is strange ...

if (err) {
    xdr.buffer = xdr.buffer.slice(pos);
    xdr.pos = 0;
    self._xdr = xdr;

    if (self.accept.protocolMinimumType === ptype_lazy_send 
            && self._queue.length > 0 
            && self._queue[0] //NEW CONDITION
            && self._queue[0].lazy_count  //NEW CONDITION ) {
        self._queue[0].lazy_count = 2;
    }
    return;
}

rscholant avatar May 12 '21 19:05 rscholant

This issue is happening here too with some queries

iget-master avatar May 27 '21 11:05 iget-master

It seems that the problem may be related to a deadlock - a concurrent update on the same row due to an uncommited transaction. You can read more here.

The error that I received when I tried to execute the statement (an update) on Firebird is:

Lock conflict on no wait transaction.
Deadlock.
Update conflicts with concurrent update.
Concurrent transaction number is 359266.

SQL Code: -901
IB Error Number: 335544345

I got this error while doing multiple (independent) inserts too, which was probably causing a deadlock when trying to access the generator for the id field.


I logged the err mentioned in the issue using console.log(err):

  console.log
    Error: Unexpected:0
        at decodeResponse (C:\mypath\node_modules\node-firebird\lib\index.js:3286:27)
        at Socket.<anonymous> (C:\mypath\node_modules\node-firebird\lib\index.js:3028:13)
        at Socket.emit (events.js:315:20)
        at addChunk (internal/streams/readable.js:309:12)
        at readableAddChunk (internal/streams/readable.js:284:9)
        at Socket.Readable.push (internal/streams/readable.js:223:10)
        at TCP.onStreamRead (internal/stream_base_commons.js:188:23)

      at node_modules/node-firebird/lib/index.js:3034:29

The 0 in the error is for the r variable in decodeResponse function. This code is for op_void "Packet has been voided". I tried to investigate further and attempted to fix it, but I didn't get anywhere.

Rafatcb avatar Aug 27 '21 14:08 Rafatcb

Did you manage to solve it?

stafocher avatar Oct 18 '22 16:10 stafocher

Hi @rscholant Can you share your code and the steps to follow to reproduce the error please?

jesusvilla avatar Nov 08 '22 03:11 jesusvilla

@jesusvilla

Hi @rscholant Can you share your code and the steps to follow to reproduce the error please?

Not OP, but I got the exact same error only by doing something extremely simple like this:

const query = (db, sql) => new Promise((resolve, reject) =>
	db.query(sql, (err, result) =>
		err ? reject(err) : resolve(result)
	)
)

// later
sqlCount = `SELECT COUNT(*) AS "count" FROM SAME_TABLE`
sqlPage = `SELECT * FROM SAME_TABLE ROWS 1 TO 20`
const [count, page] = await Promise.all([
	query(db, sqlCount),
	query(db, sqlPage)
])

rhengles avatar Dec 10 '22 15:12 rhengles

@rhengles

I find a workaround, use a different Firebird connection for parallel queries.

In your code example, the error will not occur if you use a different db for each of query.

wongjiahau avatar Feb 09 '23 03:02 wongjiahau

i have the same lazy_count problem

rodrigo-rafael avatar Jul 31 '23 00:07 rodrigo-rafael

The problem is still going on. I have the issue on a large query that fetch 1000-1500 results, each with a blob field. I have the blobastext option active in the db options with firebird 2.5. Any suggestions?

hcrufio88 avatar Feb 16 '24 17:02 hcrufio88