node-firebird
node-firebird copied to clipboard
Cannot set property 'lazy_count' of undefined
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;
}
This issue is happening here too with some queries
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) insert
s 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.
Did you manage to solve it?
Hi @rscholant Can you share your code and the steps to follow to reproduce the error please?
@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
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
.
i have the same lazy_count problem
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?