Skip to content

Commit f144a60

Browse files
committed
Improve diagnosability of internal errors with more network packet information
1 parent bd5e515 commit f144a60

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Common Changes
1717
Thin Mode Changes
1818
+++++++++++++++++
1919

20+
#) Add packet number and position in packet for some internal errors for improved diagnosability.
21+
2022
#) Fixed bug that throws the NJS-111 internal error, on the second
2123
select SQL issued after first select SQL is done on an empty
2224
table involving LOB types.

lib/errors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ messages.set(ERR_MISSING_CREDENTIALS, // NJS-101
328328
messages.set(ERR_UNEXPECTED_END_OF_DATA, // NJS-102
329329
'unexpected end of data: want %d bytes but only %d bytes are available');
330330
messages.set(ERR_UNEXPECTED_MESSAGE_TYPE, // NJS-103
331-
'unexpected message type %d received');
331+
'unexpected message type %d received at position %d of packet %d');
332332
messages.set(ERR_POOL_HAS_BUSY_CONNECTIONS, // NJS-104
333333
'connection pool cannot be closed because connections are busy');
334334
messages.set(ERR_NAN_VALUE, // NJS-105
@@ -344,9 +344,9 @@ messages.set(ERR_INVALID_TYPE_NUM, // NJS-109
344344
messages.set(ERR_INVALID_ORACLE_TYPE_NUM, // NJS-110
345345
'invalid Oracle type number %d [csfrm: %d]');
346346
messages.set(ERR_UNEXPECTED_NEGATIVE_INTEGER, // NJS-111
347-
'internal error: read a negative integer when expecting a positive integer');
347+
'internal error: read a negative integer when expecting a positive integer at position %d of packet %d');
348348
messages.set(ERR_INTEGER_TOO_LARGE, // NJS-112
349-
'internal error: read integer of length %d when expecting integer of no more than length %d');
349+
'internal error: read integer of length %d when expecting integer of no more than length %d at position %d of packet %d');
350350
messages.set(ERR_UNEXPECTED_DATA, // NJS-113
351351
'unexpected data received: %s');
352352
messages.set(ERR_OSON_FIELD_NAME_LIMITATION, // NJS-114

lib/thin/protocol/buffer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ class BaseBuffer {
9292
return 0;
9393
} else if (size & 0x80) {
9494
if (!signed) {
95-
errors.throwErr(errors.ERR_UNEXPECTED_NEGATIVE_INTEGER);
95+
errors.throwErr(errors.ERR_UNEXPECTED_NEGATIVE_INTEGER, this.pos, this.packetNum);
9696
}
9797
isNegative = true;
9898
size = size & 0x7f;
9999
}
100100
if (size > maxSize) {
101-
errors.throwErr(errors.ERR_INTEGER_TOO_LARGE, size, maxSize);
101+
errors.throwErr(errors.ERR_INTEGER_TOO_LARGE, size, maxSize, this.pos, this.packetNum);
102102
}
103103
if (skip) {
104104
this.skipBytes(size);

lib/thin/protocol/messages/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class Message {
215215
} else if (messageType === constants.TNS_MSG_TYPE_SERVER_SIDE_PIGGYBACK) {
216216
this.processServerSidePiggyBack(buf);
217217
} else {
218-
errors.throwErr(errors.ERR_UNEXPECTED_MESSAGE_TYPE, messageType);
218+
errors.throwErr(errors.ERR_UNEXPECTED_MESSAGE_TYPE, messageType, buf.pos, buf.packetNum);
219219
}
220220
}
221221

lib/thin/protocol/packet.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -254,46 +254,48 @@ class ReadPacket extends BaseBuffer {
254254
* Receives a packet from the adapter.
255255
*/
256256
receivePacket() {
257-
if (this.savedBufferPos === this.savedBuffers.length) {
257+
if (this.savedPacketPos === this.savedPackets.length) {
258258
const packet = this.nsi.syncRecvPacket();
259259
if (!packet || this.nsi.isBreak)
260260
throw new utils.OutOfPacketsError();
261-
this.savedBuffers.push(packet.buf);
261+
this.savedPackets.push(packet);
262262
}
263-
this.startPacket(this.savedBuffers[this.savedBufferPos++]);
263+
this.startPacket(this.savedPackets[this.savedPacketPos++]);
264264
}
265265

266266
restorePoint() {
267-
this.savedBufferPos = 0;
268-
this.startPacket(this.savedBuffers[this.savedBufferPos++]);
267+
this.savedPacketPos = 0;
268+
this.startPacket(this.savedPackets[this.savedPacketPos++]);
269269
this.pos = this.savedPos;
270270
}
271271

272272
savePoint() {
273-
if (this.savedBuffers) {
274-
this.savedBuffers = this.savedBuffers.splice(this.savedBufferPos - 1);
273+
if (this.savedPackets) {
274+
this.savedPackets = this.savedPackets.splice(this.savedPacketPos - 1);
275275
} else {
276-
this.savedBuffers = [this.buf];
276+
this.savedPackets = [this.packet];
277277
}
278-
this.savedBufferPos = 1;
278+
this.savedPacketPos = 1;
279279
this.savedPos = this.pos;
280280
}
281281

282-
startPacket(buf) {
283-
this.buf = buf;
282+
startPacket(packet) {
283+
this.packet = packet;
284+
this.buf = packet.buf;
284285
this.pos = 10; // skip packet heaader and data flags
285-
this.size = buf.length;
286+
this.size = packet.buf.length;
287+
this.packetNum = packet.num;
286288
}
287289

288290
async waitForPackets() {
289291
const packet = await this.nsi.recvPacket();
290-
if (!this.savedBuffers) {
291-
this.savedBuffers = [packet.buf];
292-
this.savedBufferPos = 0;
292+
if (!this.savedPackets) {
293+
this.savedPackets = [packet];
294+
this.savedPacketPos = 0;
293295
} else {
294-
this.savedBuffers.push(packet.buf);
296+
this.savedPackets.push(packet);
295297
}
296-
this.startPacket(this.savedBuffers[this.savedBufferPos++]);
298+
this.startPacket(this.savedPackets[this.savedPacketPos++]);
297299
}
298300

299301
/**

lib/thin/sqlnet/ntTcp.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const TCPCHA = 1 << 1 | /* ASYNC support */
4747
1 << 9 | /* Full Duplex support */
4848
1 << 12; /* SIGPIPE Support */
4949

50+
let streamNum = 1;
51+
5052
/**
5153
* Network Transport TCP/TCPS adapter
5254
* @param {Address} address Destination Address
@@ -63,6 +65,8 @@ class NTTCP {
6365
this.numPacketsSinceLastWait = 0;
6466
this.secure = false;
6567
this.largeSDU = false;
68+
this.streamNum = streamNum++;
69+
this.packetNum = 1;
6670
}
6771

6872
/**
@@ -319,7 +323,7 @@ class NTTCP {
319323
send(buf) {
320324
this.checkErr();
321325
if (process.env.NODE_ORACLEDB_DEBUG_PACKETS)
322-
this.printPacket("Sending packet", buf);
326+
this.printPacket(`Sending packet ${this.packetNum} on stream ${this.streamNum}`, buf);
323327
const result = this.stream.write(buf, (err) => {
324328
if (err) {
325329
this.savedErr = err;
@@ -331,6 +335,7 @@ class NTTCP {
331335
this.needsDrain = true;
332336
}
333337
this.numPacketsSinceLastWait++;
338+
this.packetNum++;
334339
}
335340

336341
/**
@@ -394,15 +399,16 @@ class NTTCP {
394399
const packet = {
395400
buf: tempBuf.subarray(0, len),
396401
type: tempBuf[4],
397-
flags: tempBuf[5]
402+
flags: tempBuf[5],
403+
num : this.packetNum++
398404
};
399405
this.packets.push(packet);
400406
if (this.readWaiter) {
401407
this.readWaiter();
402408
this.readWaiter = null;
403409
}
404410
if (process.env.NODE_ORACLEDB_DEBUG_PACKETS)
405-
this.printPacket("Receiving packet", packet.buf);
411+
this.printPacket(`Receiving packet ${packet.num} on stream ${this.streamNum}`, packet.buf);
406412

407413
// if the packet consumed all of the bytes (most common scenario), then
408414
// simply clear the temporary buffer; otherwise, retain whatever bytes

0 commit comments

Comments
 (0)