Skip to content

Commit 8abee4c

Browse files
committed
Network code improvements including patch for Issue #1564
1 parent 36d9334 commit 8abee4c

File tree

8 files changed

+68
-31
lines changed

8 files changed

+68
-31
lines changed

doc/src/release_notes.rst

+13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ node-oracledb `v6.0.3 <https://github.com/oracle/node-oracledb/compare/v6.0.2...
1111
Thin Mode Changes
1212
+++++++++++++++++
1313

14+
#) Avoid throwing errors when calls to ``os.userInfo()`` fail.
15+
`Issue #1564 <https://github.com/oracle/node-oracledb/issues/1564>`__.
16+
17+
#) Fixed error handling when invalid connect descriptor "DESCRIPTIONX" syntax was used.
18+
19+
#) Improved error message when invalid protocol was used in easyconnect syntax.
20+
21+
#) Throws an error when https_proxy is given but the protocol is tcp.
22+
23+
#) Persist in-band notifications.
24+
25+
#) Removed unused buffer.
26+
1427
#) Fixed bug to handle errors while waiting for writes to drain on the network.
1528

1629
#) Fixed bug when a break occurs in the middle of processing a database

lib/thin/protocol/messages/auth.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@
2929
const { Buffer } = require('buffer');
3030
const constants = require("../constants.js");
3131
const errors = require("../../../errors.js");
32-
const os = require("os");
3332
const process = require("process");
3433
const ED = require("../encryptDecrypt.js");
3534
const Message = require("./base.js");
3635
const util = require("../../util.js");
37-
36+
const cInfo = util.CLIENT_INFO;
3837
const crypto = require('crypto');
3938

4039
/**
@@ -184,11 +183,10 @@ class AuthMessage extends Message {
184183
buf.writeBytesWithLength(Buffer.from(this.username));
185184
}
186185
buf.writeKeyValue("AUTH_TERMINAL", "unknown");
187-
buf.writeKeyValue("AUTH_PROGRAM_NM", process.argv0);
188-
buf.writeKeyValue("AUTH_MACHINE", os.hostname());
189-
buf.writeKeyValue("AUTH_PID", process.pid.toString());
190-
buf.writeKeyValue("AUTH_SID", os.userInfo().username);
191-
186+
buf.writeKeyValue("AUTH_PROGRAM_NM", cInfo.program);
187+
buf.writeKeyValue("AUTH_MACHINE", cInfo.hostName);
188+
buf.writeKeyValue("AUTH_PID", cInfo.pid);
189+
buf.writeKeyValue("AUTH_SID", cInfo.userName);
192190
} else {
193191
let numPairs = 0;
194192

lib/thin/sqlnet/connStrategy.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
const { NavAddress, NavAddressList, NavDescription, NavDescriptionList } = require("./navNodes.js");
3030
const { createNVPair } = require("./nvStrToNvPair.js");
31-
32-
31+
const errors = require("../../errors.js");
3332

3433
/**
3534
* Class that holds all possible attributes under Description
@@ -166,6 +165,9 @@ async function createNode(str) {
166165
case "DESCRIPTION_LIST":
167166
navobj = new NavDescriptionList();
168167
break;
168+
default:
169+
errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_PARAMETERS,
170+
`unknown top element ${arg}`);
169171
}
170172
navobj.initFromNVPair(nvpair);
171173
let cs = new ConnStrategy();

lib/thin/sqlnet/ezConnectResolver.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ class EZConnectResolver {
146146
if (!(url.includes("//")))
147147
protocol = 'TCP';
148148
}
149-
150149
// Try to get the proxy information from URL properties
151150
const proxyHost = this.urlProps.get("HTTPS_PROXY");
152151
const proxyPort = this.urlProps.get("HTTPS_PROXY_PORT");
@@ -216,8 +215,12 @@ class EZConnectResolver {
216215
let ipcnt = 0;
217216
let builder = new Array();
218217
let proxyInfo = '';
219-
if (proxyHost != null && proxyPort != null) {
220-
proxyInfo = `(HTTPS_PROXY=${proxyHost})(HTTPS_PROXY_PORT=${proxyPort})`;
218+
if (proxyHost != null) {
219+
if (proxyPort != null) {
220+
proxyInfo = `(HTTPS_PROXY=${proxyHost})(HTTPS_PROXY_PORT=${proxyPort})`;
221+
} else {
222+
proxyInfo = `(HTTPS_PROXY=${proxyHost})`;
223+
}
221224
}
222225

223226
if (protocol == null) protocol = 'TCP';

lib/thin/sqlnet/navNodes.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const os = require("os");
3232
const net = require('net');
3333
const dns = require('dns');
3434
const dnsPromises = dns.promises;
35+
const cInfo = require("../util.js").CLIENT_INFO;
3536

3637
const SchemaObjectFactoryInterface = {
3738
ADDR:0,
@@ -443,7 +444,6 @@ const NavSchemaObject = {
443444
LB: "(LOAD_BALANCE=yes)",
444445
NFO: "(FAILOVER=false)",
445446
CD: "(CONNECT_DATA=",
446-
CID: `(CID=(PROGRAM=nodejs)(HOST=${os.hostname()})(USER=${os.userInfo().username}))`,
447447
CONID: "(CONNECTION_ID="
448448
};
449449
const options = {
@@ -770,10 +770,10 @@ class NavDescription extends Description {
770770
if (this.connectData == null) {
771771
this.connectData = "(SERVICE_NAME=)";
772772
}
773-
773+
const cid = `(CID=(PROGRAM=${cInfo.program})(HOST=${cInfo.hostName})(USER=${cInfo.userName}))`;
774774
cOpts[i].CNdata.push(NavSchemaObject.CD);
775775
cOpts[i].CNdata.push(this.connectData);
776-
cOpts[i].CNdata.push(NavSchemaObject.CID);
776+
cOpts[i].CNdata.push(cid);
777777
cOpts[i].CNdata.push(")");
778778

779779
if (this.SID != null) {

lib/thin/sqlnet/networkSession.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ class NetworkSession {
165165
* Make the transport level connection
166166
*/
167167
async transportConnect(address) {
168+
if (address.protocol.toUpperCase() == 'TCP' && address.httpsProxy) {
169+
errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_PARAMETERS, 'https proxy requires protocol as', 'tcps ');
170+
}
168171
if (address.protocol && (address.protocol.toUpperCase() == 'TCP' || address.protocol.toUpperCase() == 'TCPS')) {
169172
this.ntAdapter = new NTTCP(this.sAtts.nt);
170173
} else {
@@ -173,8 +176,8 @@ class NetworkSession {
173176
await this.ntAdapter.connect(address);
174177
this.ntAdapter.startRead();
175178
this.sAtts.ntCha = this.ntAdapter.cha;
176-
this.sndDatapkt = new Packet.DataPacket(this.sAtts.sdu, this.sAtts.largeSDU);
177-
this.rcvDatapkt = new Packet.DataPacket(this.sAtts.sdu, this.sAtts.largeSDU);
179+
this.sndDatapkt = new Packet.DataPacket(this.sAtts.largeSDU);
180+
this.rcvDatapkt = new Packet.DataPacket(this.sAtts.largeSDU);
178181
}
179182

180183
/**
@@ -280,17 +283,16 @@ class NetworkSession {
280283
}
281284

282285
connectPkt = new Packet.ConnectPacket(redirConnData, this.sAtts, constants.NSPFRDR);
286+
this.sndDatapkt = new Packet.DataPacket(this.sAtts.largeSDU);
283287
this._sendConnect(connectPkt);
284288
}
285289
}
286290

287291
/* Accepted */
288292
this.connected = true;
289-
this.rcvDatapkt = new Packet.DataPacket(this.sAtts.sdu, this.sAtts.largeSDU);
290-
this.rcvDatapkt.offset = this.rcvDatapkt.dataPtr;
291-
this.rcvDatapkt.len = this.rcvDatapkt.dataPtr;
292-
this.sndDatapkt = new Packet.DataPacket(this.sAtts.sdu, this.sAtts.largeSDU);
293-
this.sndDatapkt.createPacket();
293+
this.cData = null;
294+
this.sndDatapkt = new Packet.DataPacket(this.sAtts.largeSDU);
295+
this.sndDatapkt.createPacket(constants.NSPDADAT); //Currently only used for disconnect
294296
this.sndDatapkt.offset = this.sndDatapkt.dataPtr;
295297
this.sndDatapkt.len = this.sndDatapkt.bufLen;
296298
this.markerPkt = new Packet.MarkerPacket(this.sAtts.largeSDU);
@@ -466,7 +468,7 @@ class NetworkSession {
466468
let bytesCopied = 0;
467469

468470
this.sndDatapkt.dataLen = this.sndDatapkt.offset;
469-
if (this.sndDatapkt.dataLen < this.sndDatapkt.bufLen) {
471+
if (this.sndDatapkt.dataLen < this.sndDatapkt.bufLen || !this.sndDatapkt.bufLen) {
470472
bytesCopied = this.sndDatapkt.fillBuf(userBuf, offset, len);
471473
len -= bytesCopied;
472474
offset += bytesCopied;
@@ -591,7 +593,6 @@ class NetworkSession {
591593
let error = 0;
592594
if (this.controlPkt.errno) { /* Control pkt already read */
593595
error = this.controlPkt.errno;
594-
this.controlPkt.clear(); /* Clear error */
595596
return (error);
596597
} else if (!this.getOption(constants.HEALTHCHECK)) {
597598
return errors.ERR_CONNECTION_CLOSED;
@@ -602,7 +603,6 @@ class NetworkSession {
602603
if (packet.type == constants.NSPTCNL) {
603604
this.controlPkt.fromPacket(packet);
604605
error = this.controlPkt.errno;
605-
this.controlPkt.clear(); /* Clear error */
606606
return (error);
607607
} else {
608608
this.ntAdapter.packets.unshift(packet); /* Push packet back */

lib/thin/sqlnet/packet.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,24 @@ function ConnectPacket(connectData, sAtts, flags = 0) {
142142
* @param {int} size of Data Packet
143143
* @param {boolean} isLargeSDU Large SDU
144144
*/
145-
function DataPacket(size, isLargeSDU) {
145+
function DataPacket(isLargeSDU) {
146146
this.dataPtr = 0; /* data offset start */
147147
this.dataLen = 0; /* data offset end */
148-
this.bufLen = size; /* Length of buffer */
149148
this.offset = 0; /* Offset for buffer read/write (fastpath) */
150149
this.len = 0; /* Length of buffer read/write (fastpath) */
150+
this.bufLen = 0; /* Length of buffer */
151151

152152
/**
153153
* Create the Data Packet(Internal)
154154
*/
155-
this.createPacket = function() {
155+
this.createPacket = function(len) {
156156
/* Building Data Packet */
157157
this.dataPtr = constants.NSPDADAT;
158158
this.dataLen = constants.NSPDADAT;
159-
160-
this.buf = Buffer.alloc(size);
159+
this.buf = Buffer.alloc(len);
161160
this.buf.writeUInt8(0, constants.NSPHDFLGS);
162161
this.buf.writeUInt8(constants.NSPTDA, constants.NSPHDTYP);
162+
this.bufLen = len; /* Length of buffer */
163163
};
164164

165165
/**
@@ -173,7 +173,7 @@ function DataPacket(size, isLargeSDU) {
173173
let bytes2Copy;
174174

175175
if (!this.buf) {
176-
this.createPacket();
176+
this.createPacket(len + constants.NSPDADAT); //Currently NS data packets are being used only in the connect/disconnect phase
177177
}
178178

179179
if (len > this.bufLen - this.dataLen) {

lib/thin/util.js

+21
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@
2828

2929
const constants = require('../constants');
3030
const errors = require('../errors.js');
31+
const os = require('os');
32+
33+
//---------------------------------------------------------------------------
34+
// populateClientInfo()
35+
//
36+
// Populates client process information
37+
//---------------------------------------------------------------------------
38+
function populateClientInfo() {
39+
this.program = process.argv0;
40+
this.terminal = "unknown";
41+
this.pid = process.pid.toString();
42+
try {
43+
this.userName = os.userInfo().username;
44+
} catch {
45+
this.userName = "unknown";
46+
}
47+
this.hostName = os.hostname();
48+
}
49+
// Initialize client data on startup.
50+
const CLIENT_INFO = new populateClientInfo();
3151

3252
//---------------------------------------------------------------------------
3353
// getMetadataMany(sql)
@@ -280,6 +300,7 @@ function checkCredentials(params) {
280300
module.exports = {
281301
getMetadataMany,
282302
cleanSql,
303+
CLIENT_INFO,
283304
getExecuteOutBinds,
284305
getExecuteManyOutBinds,
285306
getOutBinds,

0 commit comments

Comments
 (0)