vldpyatkov commented on code in PR #10: URL: https://github.com/apache/ignite-nodejs-thin-client/pull/10#discussion_r3596298751
########## spec/cache/ColdComplexReadDeadlock.spec.js: ########## @@ -0,0 +1,165 @@ +/* + * 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 }; +} + +function withTimeout(promise, ms, message) { + let timer; + const guard = new Promise((resolve, reject) => { + timer = setTimeout(() => reject(new Error(message)), ms); + }); + return Promise.race([promise, guard]).finally(() => clearTimeout(timer)); Review Comment: Here and follow Promise.finally() constructions are used, but it is implemented only in Node.js 10 (Node.js >= 8 is declared). So, it ought to be rewritten to a plain try - finally. -- 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]
