You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by zs...@apache.org on 2026/08/13 05:41:52 UTC
(ignite-nodejs-thin-client) branch master updated (fa2a0ba -> df0fe4c)
This is an automated email from the ASF dual-hosted git repository.
zstan pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-nodejs-thin-client.git
discard fa2a0ba Merge pull request #10 from JohnSColeman/master
omit 85ff8ca Reject in-flight request when detached finalize throws; drop Promise.finally in specs
omit ac6092a Drop the version bump from this bug-fix PR
omit bfcf03d Return an empty array from Cursor._getValues() on exhaustion
omit 0fd725b Dispatch _finalizeResponse off the processing queue to avoid deadlock
omit 92a22d6 Fail fast on response stream desync instead of discarding the frame
omit 54c6032 Clarify per-message buffer comment: copy happens in MessageBuffer.from
omit 28b76f3 Build per-message buffer only on the matched-request path
omit b5e735e Warn (not silently discard) on response frame with unmatched request id
omit bd33cba Use MessageBuffer.getSlice() helper when carving per-message buffer
omit 952ce79 Fix BaseCursor _id typing and hasMore() on empty results
omit 86a7ed1 fix defects bump version to 1.1.1
omit 2031e68 IGNITE-18520 Await cluster start by logs in tests
omit dc5fd9f IGNITE-18520 Await cluster start by logs
omit bfd0be0 IGNITE-19421 Added extended debug logging of client connections
omit 341bb01 IGNITE-19421 Added extended debug logging of client connections
omit 8e8c376 Merge pull request #7 from apache/ignite-15759
omit 8701f16 IGNITE-15759 Replace local affinity function with the custom one
omit 618d032 IGNITE-17389 Increase test node startup timeout
omit a664d1b IGNITE-17389 Increase test node startup timeout
omit 4669930 IGNITE-16651 Use ignite-log4j2 logger instead of deprecated ignite-log4j
new 0c7c3c7 IGNITE-17389 Increase test node startup timeout
new fb71360 IGNITE-15759 Replace local affinity function with the custom one
new fce3c8a IGNITE-19421 Added extended debug logging of client connections
new a538d74 IGNITE-18520 Await cluster start by logs
new df0fe4c IGNITE-14550 Fix four bugs in ClientSocket, Cursor and Errors
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (fa2a0ba)
\
N -- N -- N refs/heads/master (df0fe4c)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
(ignite-nodejs-thin-client) 05/05: IGNITE-14550 Fix four bugs in ClientSocket, Cursor and Errors
Posted by zs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zstan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-nodejs-thin-client.git
commit df0fe4cfdcf55278c07787d8cd456d29dd5fd00b
Author: JohnSColeman <qb...@gmail.com>
AuthorDate: Sun Apr 5 19:01:42 2026 +0700
IGNITE-14550 Fix four bugs in ClientSocket, Cursor and Errors
---
spec/cache/ColdComplexRead.spec.js | 136 +++++++++++++++++++++++
spec/cache/ColdComplexReadDeadlock.spec.js | 171 +++++++++++++++++++++++++++++
src/Cursor.ts | 39 ++++++-
src/Errors.ts | 6 +-
src/internal/ClientSocket.ts | 111 ++++++++++++++++---
5 files changed, 439 insertions(+), 24 deletions(-)
diff --git a/spec/cache/ColdComplexRead.spec.js b/spec/cache/ColdComplexRead.spec.js
new file mode 100644
index 0000000..348c920
--- /dev/null
+++ b/spec/cache/ColdComplexRead.spec.js
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+require('jasmine-expect');
+
+const TestingHelper = require('../TestingHelper');
+const {
+ IgniteClientConfiguration, ObjectType, ComplexObjectType
+} = require('apache-ignite-client');
+
+const CACHE_NAME = '__test_cold_complex_read';
+
+// Deadlock guard: a fresh client reading a complex object whose binary type is
+// not yet in its own BinaryTypeStorage must issue a nested GET_BINARY_TYPE on the
+// same socket from inside the get() payloadReader. If response finalization is
+// awaited on the socket processing queue, that nested reply can never be parsed
+// and get() hangs forever, so we race it against an explicit timeout.
+const DEADLOCK_TIMEOUT_MS = 10000;
+
+class ColdValue {
+ constructor() {
+ this.id = null;
+ this.name = null;
+ }
+}
+
+function coldValueType() {
+ return new ComplexObjectType(new ColdValue(), 'ColdValue').
+ setFieldType('id', ObjectType.PRIMITIVE_TYPE.INTEGER).
+ setFieldType('name', ObjectType.PRIMITIVE_TYPE.STRING);
+}
+
+async function withTimeout(promise, ms, message) {
+ let timer;
+ const guard = new Promise((resolve, reject) => {
+ timer = setTimeout(() => reject(new Error(message)), ms);
+ });
+ // try/finally rather than Promise.prototype.finally, which is Node 10+
+ // (package.json declares engines.node >= 8.0.0).
+ try {
+ return await Promise.race([promise, guard]);
+ } finally {
+ clearTimeout(timer);
+ }
+}
+
+describe('cold complex object read test suite >', () => {
+ let igniteClient = null;
+
+ beforeAll((done) => {
+ Promise.resolve().
+ then(async () => {
+ await TestingHelper.init();
+ igniteClient = TestingHelper.igniteClient;
+ await igniteClient.destroyCache(CACHE_NAME).catch(() => {});
+ await igniteClient.getOrCreateCache(CACHE_NAME);
+ }).
+ then(done).
+ catch(error => done.fail(error));
+ }, TestingHelper.TIMEOUT);
+
+ afterAll((done) => {
+ Promise.resolve().
+ then(async () => {
+ if (igniteClient) {
+ await igniteClient.destroyCache(CACHE_NAME).catch(() => {});
+ }
+ await TestingHelper.cleanUp();
+ }).
+ then(done).
+ catch(error => done.fail(error));
+ }, TestingHelper.TIMEOUT);
+
+ it('fresh client reads a complex object it did not write without deadlock', (done) => {
+ let clientB = null;
+ Promise.resolve().
+ then(async () => {
+ const key = 1;
+ const value = new ColdValue();
+ value.id = 42;
+ value.name = 'cold-read';
+
+ // Writer client A: put registers the binary type in A's own type
+ // storage (addType) and on the server, but NOT in any other client.
+ const cacheA = igniteClient.getCache(CACHE_NAME).
+ setValueType(coldValueType());
+ await cacheA.put(key, value);
+
+ // Reader client B: a separate, freshly-connected client whose
+ // BinaryTypeStorage._types is empty, so reading the value forces a
+ // nested GET_BINARY_TYPE on B's single socket — the cold path that
+ // the existing suites never exercise (they put before they read on
+ // the same client, making getType a cache hit).
+ clientB = TestingHelper.makeClient();
+ const endpoints = TestingHelper.getEndpoints(1);
+ await clientB.connect(new IgniteClientConfiguration(...endpoints).
+ setConnectionOptions(false, null, false));
+
+ const cacheB = clientB.getCache(CACHE_NAME).
+ setValueType(coldValueType());
+
+ const result = await withTimeout(
+ cacheB.get(key),
+ DEADLOCK_TIMEOUT_MS,
+ 'cache.get() of an uncached complex object did not resolve within ' +
+ DEADLOCK_TIMEOUT_MS + 'ms — the response processing queue deadlocked');
+
+ expect(result).not.toBeNull();
+ expect(result.id).toBe(value.id);
+ expect(result.name).toBe(value.name);
+ }).
+ then(done).
+ catch(error => done.fail(error)).
+ then(async () => {
+ if (clientB) {
+ await clientB.disconnect();
+ }
+ });
+ }, TestingHelper.TIMEOUT);
+});
diff --git a/spec/cache/ColdComplexReadDeadlock.spec.js b/spec/cache/ColdComplexReadDeadlock.spec.js
new file mode 100644
index 0000000..176e0e0
--- /dev/null
+++ b/spec/cache/ColdComplexReadDeadlock.spec.js
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+require('jasmine-expect');
+
+const net = require('net');
+const EventEmitter = require('events');
+const Long = require('long');
+
+// Drive the REAL ClientSocket against a mock TCP socket so this regression is
+// deterministic and needs no cluster. It reproduces the exact async topology of
+// the cold complex-object read: a single socket, one response whose payloadReader
+// issues a nested request on that same socket and awaits its reply, where the
+// reply only arrives as a later 'data' event. If response finalization is awaited
+// on the socket's serialized processing queue, the nested reply is chained behind
+// the still-pending outer entry and can never be processed -> the outer request
+// hangs forever. With finalization dispatched off the queue, it resolves.
+const ClientSocket = require('apache-ignite-client/dist/internal/ClientSocket').default;
+const MessageBuffer = require('apache-ignite-client/dist/internal/MessageBuffer').default;
+
+const HANDSHAKE_SUCCESS_STATUS_CODE = 1;
+const OP_OUTER = 2001;
+const OP_INNER = 2002;
+const DEADLOCK_TIMEOUT_MS = 5000;
+
+// Handshake reply frame: [length:int][status:byte]. The >= 1.4.0 path then reads a
+// node-UUID via communicator.readObject, which the mock communicator stubs out, so
+// no UUID bytes are required (frames are length-delimited, not reader-position
+// delimited).
+function buildHandshakeResponse() {
+ const buf = new MessageBuffer();
+ buf.position = 4;
+ buf.writeByte(HANDSHAKE_SUCCESS_STATUS_CODE);
+ const len = buf.length - 4;
+ buf.position = 0;
+ buf.writeInteger(len);
+ return buf.data;
+}
+
+// Success response frame for protocol >= 1.4.0: [length:int][requestId:long][flags:short=0].
+function buildResponse(requestId) {
+ const buf = new MessageBuffer();
+ buf.position = 4;
+ buf.writeLong(requestId);
+ buf.writeShort(0);
+ const len = buf.length - 4;
+ buf.position = 0;
+ buf.writeInteger(len);
+ return buf.data;
+}
+
+// Outgoing request frame layout (see ClientSocket Request.getMessage):
+// [length:int][opCode:short][requestId:long][payload].
+function parseOutgoing(data) {
+ const buf = MessageBuffer.from(data, 0);
+ buf.readInteger();
+ const opCode = buf.readShort();
+ const requestId = buf.readLong();
+ return { opCode, requestId };
+}
+
+async function withTimeout(promise, ms, message) {
+ let timer;
+ const guard = new Promise((resolve, reject) => {
+ timer = setTimeout(() => reject(new Error(message)), ms);
+ });
+ // try/finally rather than Promise.prototype.finally, which is Node 10+
+ // (package.json declares engines.node >= 8.0.0).
+ try {
+ return await Promise.race([promise, guard]);
+ } finally {
+ clearTimeout(timer);
+ }
+}
+
+describe('cold complex object read deadlock (mock socket) test suite >', () => {
+ let origCreateConnection;
+
+ beforeEach(() => {
+ origCreateConnection = net.createConnection;
+ });
+
+ afterEach(() => {
+ net.createConnection = origCreateConnection;
+ });
+
+ it('response whose payloadReader awaits a nested same-socket request resolves', (done) => {
+ let clientSocket = null;
+ Promise.resolve().
+ then(async () => {
+ const mockSocket = new EventEmitter();
+ mockSocket.end = () => {};
+
+ let handshakeSent = false;
+ mockSocket.write = (data) => {
+ if (!handshakeSent) {
+ // First write is the handshake (no opCode/id).
+ handshakeSent = true;
+ setImmediate(() => mockSocket.emit('data', buildHandshakeResponse()));
+ return true;
+ }
+ // Every subsequent request gets its reply on a LATER event loop
+ // tick — modelling the real "reply arrives as a future data event"
+ // ordering, including the nested request the outer reader issues.
+ const { opCode, requestId } = parseOutgoing(data);
+ if (opCode === OP_OUTER || opCode === OP_INNER) {
+ setImmediate(() => mockSocket.emit('data', buildResponse(requestId)));
+ }
+ return true;
+ };
+
+ net.createConnection = (options, onConnected) => {
+ setImmediate(onConnected);
+ return mockSocket;
+ };
+
+ const config = { options: {}, useTLS: false };
+ const communicator = { readObject: async () => null };
+ clientSocket = new ClientSocket(
+ '127.0.0.1:10800', config, communicator, () => {}, async () => {});
+
+ await withTimeout(clientSocket.connect(), DEADLOCK_TIMEOUT_MS,
+ 'handshake did not complete');
+
+ let nestedIssued = false;
+ let nestedResolved = false;
+ const outer = clientSocket.sendRequest(
+ OP_OUTER,
+ async () => {},
+ async (buffer) => {
+ // Inline read of the outer response issues a nested request on
+ // this same socket and awaits it — exactly what readObject does
+ // for a COMPLEX_OBJECT whose binary type is not yet cached.
+ nestedIssued = true;
+ await clientSocket.sendRequest(OP_INNER, async () => {}, async () => {});
+ nestedResolved = true;
+ });
+
+ await withTimeout(outer, DEADLOCK_TIMEOUT_MS,
+ 'outer request did not resolve within ' + DEADLOCK_TIMEOUT_MS +
+ 'ms — the response processing queue deadlocked on the nested ' +
+ 'same-socket request');
+
+ expect(nestedIssued).toBe(true);
+ expect(nestedResolved).toBe(true);
+ }).
+ then(done).
+ catch(error => done.fail(error)).
+ then(() => {
+ if (clientSocket) {
+ try { clientSocket.disconnect(); } catch (_e) { /* ignore */ }
+ }
+ });
+ });
+});
diff --git a/src/Cursor.ts b/src/Cursor.ts
index 30bdc0a..75ed342 100644
--- a/src/Cursor.ts
+++ b/src/Cursor.ts
@@ -17,7 +17,7 @@
'use strict';
-const Long = require('long');
+import Long = require('long');
import BinaryUtils, { OPERATION } from './internal/BinaryUtils';
import BinaryCommunicator from "./internal/BinaryCommunicator";
import {PRIMITIVE_TYPE} from "./internal/Constants";
@@ -74,8 +74,28 @@ export abstract class BaseCursor<T> {
* @return {boolean} - true if more cache entries are available, false otherwise.
*/
hasMore(): boolean {
- return this._hasNext ||
- this._values && this._valueIndex < this._values.length;
+ if (this._hasNext) {
+ return true;
+ }
+ if (this._values != null && this._valueIndex < this._values.length) {
+ return true;
+ }
+ if (this._buffer != null) {
+ // Peek the buffered first page without consuming it. A page is laid out as
+ // [rowCount:int][rows...][hasNext:bool]; rowCount === 0 with a trailing
+ // hasNext === false is an empty result, so hasMore() must be false here.
+ const savedPosition = this._buffer.position;
+ try {
+ const rowCount = this._buffer.readInteger();
+ return rowCount > 0 || this._buffer.readBoolean();
+ }
+ finally {
+ // Restore even if a read throws on a short/truncated page, so the
+ // peek never advances the buffer position (keeps hasMore() total).
+ this._buffer.position = savedPosition;
+ }
+ }
+ return false;
}
/**
@@ -160,8 +180,17 @@ export abstract class BaseCursor<T> {
if (!this._buffer && this._hasNext) {
await this._getNext();
}
- await this._read(this._buffer)
- this._buffer = null;
+ if (this._buffer) {
+ await this._read(this._buffer);
+ this._buffer = null;
+ } else {
+ // No buffer and no next page — cursor is exhausted. Return an empty
+ // array (not null) to honour the declared Promise<T[]> contract: an
+ // exhausted cursor has no more entries, not a missing collection.
+ // getValue() still returns null naturally (length 0) and hasMore()
+ // stays false, so old entries are never replayed.
+ this._values = [];
+ }
return this._values;
}
diff --git a/src/Errors.ts b/src/Errors.ts
index 30ee6f6..789767e 100644
--- a/src/Errors.ts
+++ b/src/Errors.ts
@@ -32,7 +32,7 @@ export class IgniteClientError extends Error {
* @ignore
*/
static unsupportedTypeError(type) {
- const BinaryUtils = require('./internal/BinaryUtils');
+ const BinaryUtils = require('./internal/BinaryUtils').default;
return new IgniteClientError(Util.format('Type %s is not supported', BinaryUtils.getTypeName(type)));
}
@@ -41,7 +41,7 @@ export class IgniteClientError extends Error {
* @ignore
*/
static typeCastError(fromType, toType) {
- const BinaryUtils = require('./internal/BinaryUtils');
+ const BinaryUtils = require('./internal/BinaryUtils').default;
return new IgniteClientError(Util.format('Type "%s" can not be cast to %s',
BinaryUtils.getTypeName(fromType), BinaryUtils.getTypeName(toType)));
}
@@ -51,7 +51,7 @@ export class IgniteClientError extends Error {
* @ignore
*/
static valueCastError(value, toType) {
- const BinaryUtils = require('./internal/BinaryUtils');
+ const BinaryUtils = require('./internal/BinaryUtils').default;
return new IgniteClientError(Util.format('Value "%s" can not be cast to %s',
value, BinaryUtils.getTypeName(toType)));
}
diff --git a/src/internal/ClientSocket.ts b/src/internal/ClientSocket.ts
index e9a1074..5af139b 100644
--- a/src/internal/ClientSocket.ts
+++ b/src/internal/ClientSocket.ts
@@ -86,7 +86,6 @@ class ProtocolVersion {
}
}
-const PROTOCOL_VERSION_1_0_0 = new ProtocolVersion(1, 0, 0);
const PROTOCOL_VERSION_1_1_0 = new ProtocolVersion(1, 1, 0);
const PROTOCOL_VERSION_1_2_0 = new ProtocolVersion(1, 2, 0);
const PROTOCOL_VERSION_1_3_0 = new ProtocolVersion(1, 3, 0);
@@ -136,6 +135,7 @@ export default class ClientSocket {
private _protocolVersion: ProtocolVersion;
private _port: number | string;
private _version: number;
+ private _processingQueue: Promise<void>;
constructor(endpoint: string, config: IgniteClientConfiguration, communicator: BinaryCommunicator, onSocketDisconnect: Function, onAffinityTopologyChange: Function) {
ArgumentChecker.notEmpty(endpoint, 'endpoints');
@@ -158,6 +158,7 @@ export default class ClientSocket {
this._error = null;
this._nodeUuid = null;
+ this._processingQueue = Promise.resolve();
}
async connect() {
@@ -216,14 +217,19 @@ export default class ClientSocket {
this._socket = net.createConnection(<NetConnectOpts>options, onConnected);
}
- this._socket.on('data', async (data: Buffer) => {
- try {
- await this._processResponse(data);
- }
- catch (err) {
- this._error = err.message;
- this._disconnect();
- }
+ // Serialize response processing — each 'data' event is chained onto the
+ // previous one so that _processResponse never runs concurrently. This
+ // protects the synchronous frame-splitting that mutates the shared
+ // _buffer/_offset state, and the awaited handshake finalize. Matched
+ // responses are finalized off this chain (see _processResponse) so that a
+ // payloadReader's nested same-socket request cannot deadlock the queue.
+ this._socket.on('data', (data: Buffer) => {
+ this._processingQueue = this._processingQueue
+ .then(() => this._processResponse(data))
+ .catch(err => {
+ this._error = err.message;
+ this._disconnect();
+ });
});
this._socket.on('close', () => {
this._disconnect(false);
@@ -266,6 +272,13 @@ export default class ClientSocket {
while (this._buffer && this._offset < this._buffer.length) {
const buffer = this._buffer;
+
+ // Always start each message parse from the correct position.
+ // A previous payloadReader may have consumed only part of the prior
+ // message payload (e.g. a scan cursor only reads the cursor-ID), so
+ // buffer.position could be anywhere inside the previous message.
+ buffer.position = this._offset;
+
// Response length
const length = buffer.readInteger() + BinaryUtils.getSize(BinaryUtils.TYPE_CODE.INTEGER);
@@ -286,7 +299,14 @@ export default class ClientSocket {
requestId = buffer.readLong().toString();
}
- this._logMessage(requestId, false, buffer.getSlice(this._offset - length, length));
+ // Record boundaries before the socket buffer is potentially cleared.
+ // getSlice(start, end) takes an end offset, not a length, so the message
+ // bytes are [msgStart, msgEnd); passing `length` as the end logs empty
+ // bytes for any 2nd+ frame in a segment (where msgStart > 0).
+ const msgEnd = this._offset;
+ const msgStart = msgEnd - length;
+
+ this._logMessage(requestId, false, buffer.getSlice(msgStart, msgEnd));
if (this._offset === buffer.length) {
this._buffer = null;
@@ -296,15 +316,74 @@ export default class ClientSocket {
if (this._requests.has(requestId)) {
const request = this._requests.get(requestId);
this._requests.delete(requestId);
+
+ // Carve a fresh, independent MessageBuffer from just this message's
+ // payload bytes (after length field + request-id). getSlice() returns
+ // a view over the shared socket buffer, but MessageBuffer.from() copies
+ // those bytes (via Buffer.from), so freshBuffer owns an independent
+ // buffer with its own position pointer. That independence prevents two
+ // cursors created from the same TCP segment from aliasing the same
+ // position and corrupting each other's reads under parallel scan
+ // workloads. Built only on the matched-request path so unmatched frames
+ // cost no copy.
+ const headerConsumed = isHandshake
+ ? BinaryUtils.getSize(BinaryUtils.TYPE_CODE.INTEGER) // 4 B: length only
+ : BinaryUtils.getSize(BinaryUtils.TYPE_CODE.INTEGER) + // 4 B: length
+ BinaryUtils.getSize(BinaryUtils.TYPE_CODE.LONG); // 8 B: request-id
+ const freshBuffer = MessageBuffer.from(
+ buffer.getSlice(msgStart + headerConsumed, msgEnd),
+ 0
+ );
+
if (isHandshake) {
- await this._finalizeHandshake(buffer, request);
+ // Handshake is single-in-flight, transitions _state and issues no
+ // nested request, so it is safe to await inline on the queue.
+ await this._finalizeHandshake(freshBuffer, request);
}
else {
- await this._finalizeResponse(buffer, request);
+ // Do NOT await on the processing queue: a payloadReader may issue a
+ // nested request on this same socket and await its reply (e.g.
+ // GET_BINARY_TYPE when reading a COMPLEX_OBJECT whose type is not yet
+ // cached in this client's BinaryTypeStorage). That reply arrives as a
+ // later 'data' event chained behind this very queue entry, so awaiting
+ // here would deadlock — the entry can only complete once the reply is
+ // processed, but the reply can only be processed by a later entry.
+ // freshBuffer is an independent copy of this message's payload, so
+ // finalizing it off the parse chain cannot corrupt _buffer/_offset.
+ // With finalize detached the CONNECTED path of _processResponse has no
+ // remaining await and runs to completion synchronously, so two
+ // invocations still cannot interleave on _buffer/_offset and the parse
+ // race stays closed.
+ this._finalizeResponse(freshBuffer, request).catch(err => {
+ // `request` was already removed from _requests above, so the
+ // _disconnect() below cannot reject it. _finalizeResponse has
+ // throw paths outside its own try/catch (the header reads and
+ // _onAffinityTopologyChange), so an error here would otherwise
+ // leave the caller awaiting this request forever. Reject it
+ // explicitly first. If _finalizeResponse already settled the
+ // request, this reject is a harmless no-op.
+ request.reject(err);
+ this._error = err.message;
+ this._disconnect();
+ });
}
}
else {
- throw IgniteClientError.internalError('Invalid response id: ' + requestId);
+ // No pending request matches this response id. At the protocol version
+ // this client negotiates (<= 1.4.0) the server never sends unsolicited
+ // frames: affinity-topology updates ride on response flags (handled in
+ // _finalizeResponse), and notification / heartbeat frames only exist in
+ // later protocol versions this client does not speak. Requests are also
+ // never removed while still awaiting a response (there is no client-side
+ // timeout), so an unmatched id cannot be a late or duplicate reply.
+ // It therefore means the response byte stream has desynced, after which
+ // every subsequent frame is garbage and the originating request would
+ // otherwise hang forever. Fail fast: throwing propagates to the socket
+ // 'data' handler's catch, which disconnects and rejects all pending
+ // requests with LostConnectionError so callers can recover instead of
+ // hanging.
+ throw IgniteClientError.internalError(
+ 'Response stream desync: received a frame with unmatched request id ' + requestId);
}
}
}
@@ -350,11 +429,11 @@ export default class ClientSocket {
}
async _finalizeResponse(buffer: MessageBuffer, request: Request) {
- let statusCode, isSuccess;
+ let isSuccess;
if (this._protocolVersion.compareTo(PROTOCOL_VERSION_1_4_0) < 0) {
// Check status code
- statusCode = buffer.readInteger();
+ const statusCode = buffer.readInteger();
isSuccess = statusCode === REQUEST_SUCCESS_STATUS_CODE;
}
else {
@@ -368,7 +447,7 @@ export default class ClientSocket {
}
if (!isSuccess) {
- statusCode = buffer.readInteger();
+ buffer.readInteger(); // advance past status code; error detail is in the message string
}
}
(ignite-nodejs-thin-client) 03/05: IGNITE-19421 Added extended debug logging of client connections
Posted by zs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zstan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-nodejs-thin-client.git
commit fce3c8abb6a0672bfddfc46510c6ae5c854aaa2a
Author: NSAmelchev <ns...@gmail.com>
AuthorDate: Sun May 7 11:32:23 2023 +0300
IGNITE-19421 Added extended debug logging of client connections
---
spec/configs/log4j2-1.xml | 2 +-
spec/configs/log4j2-2.xml | 2 +-
spec/configs/log4j2-3.xml | 2 +-
spec/configs/log4j2-4.xml | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/spec/configs/log4j2-1.xml b/spec/configs/log4j2-1.xml
index e391192..9fb6193 100644
--- a/spec/configs/log4j2-1.xml
+++ b/spec/configs/log4j2-1.xml
@@ -44,7 +44,7 @@
</Appenders>
<Loggers>
- <Logger name="org.apache.ignite.internal.processors.odbc.ClientListenerNioListener" level="DEBUG"/>
+ <Logger name="org.apache.ignite.internal.processors.odbc.ClientListenerNioListener" level="TRACE"/>
<Root level="INFO">
<AppenderRef ref="CONSOLE"/>
diff --git a/spec/configs/log4j2-2.xml b/spec/configs/log4j2-2.xml
index 90a80ea..44230d0 100644
--- a/spec/configs/log4j2-2.xml
+++ b/spec/configs/log4j2-2.xml
@@ -44,7 +44,7 @@
</Appenders>
<Loggers>
- <Logger name="org.apache.ignite.internal.processors.odbc.ClientListenerNioListener" level="DEBUG"/>
+ <Logger name="org.apache.ignite.internal.processors.odbc.ClientListenerNioListener" level="TRACE"/>
<Root level="INFO">
<AppenderRef ref="CONSOLE"/>
diff --git a/spec/configs/log4j2-3.xml b/spec/configs/log4j2-3.xml
index 5212130..98c9d14 100644
--- a/spec/configs/log4j2-3.xml
+++ b/spec/configs/log4j2-3.xml
@@ -44,7 +44,7 @@
</Appenders>
<Loggers>
- <Logger name="org.apache.ignite.internal.processors.odbc.ClientListenerNioListener" level="DEBUG"/>
+ <Logger name="org.apache.ignite.internal.processors.odbc.ClientListenerNioListener" level="TRACE"/>
<Root level="INFO">
<AppenderRef ref="CONSOLE"/>
diff --git a/spec/configs/log4j2-4.xml b/spec/configs/log4j2-4.xml
index ef36d3d..b989007 100644
--- a/spec/configs/log4j2-4.xml
+++ b/spec/configs/log4j2-4.xml
@@ -44,7 +44,7 @@
</Appenders>
<Loggers>
- <Logger name="org.apache.ignite.internal.processors.odbc.ClientListenerNioListener" level="DEBUG"/>
+ <Logger name="org.apache.ignite.internal.processors.odbc.ClientListenerNioListener" level="TRACE"/>
<Root level="INFO">
<AppenderRef ref="CONSOLE"/>
(ignite-nodejs-thin-client) 02/05: IGNITE-15759 Replace local affinity function with the custom one
Posted by zs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zstan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-nodejs-thin-client.git
commit fb7136000b39f81f47d98c4f9165980af42bc185
Author: Maxim Muzafarov <ma...@gmail.com>
AuthorDate: Thu Aug 11 14:28:32 2022 +0300
IGNITE-15759 Replace local affinity function with the custom one
---
spec/configs/ignite-config-base.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/spec/configs/ignite-config-base.xml b/spec/configs/ignite-config-base.xml
index f4bd067..99ad7f7 100644
--- a/spec/configs/ignite-config-base.xml
+++ b/spec/configs/ignite-config-base.xml
@@ -59,7 +59,7 @@
<property name="cacheMode" value="PARTITIONED"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="affinity">
- <bean class="org.apache.ignite.internal.processors.affinity.LocalAffinityFunction"/>
+ <bean class="org.apache.ignite.compatibility.clients.JavaThinCompatibilityTest.CustomAffinity"/>
</property>
</bean>
(ignite-nodejs-thin-client) 04/05: IGNITE-18520 Await cluster start by logs
Posted by zs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zstan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-nodejs-thin-client.git
commit a538d7418067b722806fe2830231316522784cd3
Author: Nikita Amelchev <na...@apache.org>
AuthorDate: Wed Nov 20 23:30:34 2024 +0300
IGNITE-18520 Await cluster start by logs
---
spec/TestingHelper.js | 31 +++++++------------------------
1 file changed, 7 insertions(+), 24 deletions(-)
diff --git a/spec/TestingHelper.js b/spec/TestingHelper.js
index 7fa1c0d..ed3d86e 100644
--- a/spec/TestingHelper.js
+++ b/spec/TestingHelper.js
@@ -304,27 +304,6 @@ class TestingHelper {
}
}
- static async tryConnectClient(idx = 1, debug = false) {
- const endPoint = Util.format('127.0.0.1:%d', 10800 + idx);
-
- TestingHelper.logDebug('Checking endpoint: ' + endPoint);
-
- let cli = new IgniteClient();
- cli.setDebug(debug);
-
- return await cli.connect(new IgniteClientConfiguration(endPoint).
- setConnectionOptions(false, null, false)).
- then(() => {
- TestingHelper.logDebug('Successfully connected');
- cli.disconnect();
- return true;
- }).
- catch(error => {
- TestingHelper.logDebug('Error while connecting: ' + error.toString());
- return false;
- });
- }
-
static async startTestServers(needLogging, serversNum) {
TestingHelper.logDebug('Starting ' + serversNum + ' node[s]');
if (serversNum < 0)
@@ -500,6 +479,8 @@ class TestingHelper {
const nodeCfg = TestingHelper.getConfigPath(needLogging, idx);
TestingHelper.logDebug('Trying to start node using following command: ' + runner + ' ' + nodeCfg);
+ let nodeStarted = false;
+
const srv = child_process.spawn(runner, [nodeCfg], {env: nodeEnv});
srv.on('error', (error) => {
@@ -510,6 +491,9 @@ class TestingHelper {
srv.stdout.on('data', (data) => {
if (config.nodeDebug)
console.log(data.toString());
+
+ if (data.toString().includes("Topology snapshot"))
+ nodeStarted = true;
});
srv.stderr.on('data', (data) => {
@@ -517,12 +501,11 @@ class TestingHelper {
console.error(data.toString());
});
- const started = await TestingHelper.waitForCondition(async () =>
- TestingHelper.tryConnectClient(idx), 30000);
+ const started = await TestingHelper.waitForCondition(async () => nodeStarted, 30000);
if (!started) {
await TestingHelper.killNodeAndWait(srv);
- throw 'Failed to start Node: timeout while trying to connect';
+ throw 'Failed to start Node within timeout';
}
return srv;
(ignite-nodejs-thin-client) 01/05: IGNITE-17389 Increase test node startup timeout
Posted by zs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zstan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-nodejs-thin-client.git
commit 0c7c3c76688d34065253713c917b0d388b36ad83
Author: Igor Sapego <is...@apache.org>
AuthorDate: Tue Jul 5 11:06:52 2022 +0400
IGNITE-17389 Increase test node startup timeout
---
README.md | 2 ++
package.json | 2 +-
spec/TestingHelper.js | 10 ++++++----
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 13d2cc0..5cf5d1f 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,8 @@ This way is more suitable for developers or if you install client from zip archi
```bash
cd nodejs-thin-client
+npm install
+npm run build
npm link
npm link apache-ignite-client #linking examples (optional)
```
diff --git a/package.json b/package.json
index 57082ea..f46876d 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
"devDependencies": {
"jasmine": "3.6.2",
"jasmine-expect": "5.0.0",
- "jasmine-reporters": "2.3.2",
+ "jasmine-reporters": "2.5.0",
"ps-tree": "1.2.0",
"process-exists": "4.0.0",
"glob": "7.1.6",
diff --git a/spec/TestingHelper.js b/spec/TestingHelper.js
index 83b2c8c..7fa1c0d 100644
--- a/spec/TestingHelper.js
+++ b/spec/TestingHelper.js
@@ -297,7 +297,7 @@ class TestingHelper {
while (!await cond()) {
if (Date.now() - startTime > timeout) {
- throw 'Failed to achive condition within timeout ' + timeout;
+ throw 'Failed to achieve condition within timeout ' + timeout;
}
await TestingHelper.sleep(100);
@@ -348,7 +348,7 @@ class TestingHelper {
throw 'Unexpected log file for node ' + idx;
if (needLogging) {
- if (logs.length != 1)
+ if (logs.length !== 1)
throw 'Unexpected number of log files for node ' + idx + ': ' + logs.length;
TestingHelper._logReaders.set(idx, new LogReader(logs[0]));
@@ -386,16 +386,18 @@ class TestingHelper {
}
static killNode(proc) {
+ TestingHelper.logDebug('Killing Ignite process: ' + proc.pid);
if (TestingHelper.isWindows()) {
child_process.spawnSync('taskkill', ['/F', '/T', '/PID', proc.pid.toString()])
}
psTree(proc.pid, function (err, children) {
children.map((p) => {
+ TestingHelper.logDebug('Killing Ignite process child: ' + p.PID);
try {
process.kill(p.PID, 'SIGKILL');
}
catch (_error) {
- // No-op.
+ TestingHelper.logDebug('Can not kill Ignite process child: ' + _error.toString());
}
});
});
@@ -516,7 +518,7 @@ class TestingHelper {
});
const started = await TestingHelper.waitForCondition(async () =>
- TestingHelper.tryConnectClient(idx), 10000);
+ TestingHelper.tryConnectClient(idx), 30000);
if (!started) {
await TestingHelper.killNodeAndWait(srv);