JohnSColeman commented on code in PR #10:
URL: 
https://github.com/apache/ignite-nodejs-thin-client/pull/10#discussion_r3468491237


##########
src/internal/ClientSocket.ts:
##########
@@ -296,15 +311,40 @@ 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).  Passing a 
copy
+                // rather than the shared socket buffer prevents two cursors 
created
+                // from the same TCP segment from aliasing the same position 
pointer
+                // 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);
+                    await this._finalizeHandshake(freshBuffer, request);
                 }
                 else {
-                    await this._finalizeResponse(buffer, request);
+                    await this._finalizeResponse(freshBuffer, request);
                 }
             }
             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 has no 
reason
+                // to send an unsolicited frame: 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. An unmatched id therefore most likely 
indicates a
+                // parsing desync. Discard it so the connection survives 
instead of
+                // crashing, but warn (when debug is enabled) so the anomaly is
+                // diagnosable rather than silently masked.
+                Logger.logWarning('Discarding response frame with unmatched 
request id: ' + requestId);

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to