Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sendCommand(command, stream, node) {
if (this.status === "wait") {
this.connect().catch(noop);
}
if (this.status === "end") {
command.reject(new Error(CONNECTION_CLOSED_ERROR_MSG));
return command.promise;
}
let to = this.options.scaleReads;
if (to !== "master") {
const isCommandReadOnly =
commands.exists(command.name) &&
commands.hasFlag(command.name, "readonly");
if (!isCommandReadOnly) {
to = "master";
}
}
let targetSlot = node ? node.slot : command.getSlot();
const ttl = {};
const _this = this;
if (!node && !command.__is_reject_overwritten) {
// eslint-disable-next-line @typescript-eslint/camelcase
command.__is_reject_overwritten = true;
const reject = command.reject;
command.reject = function(err) {
const partialTry = tryConnection.bind(null, true);
_this.handleError(err, ttl, {
moved: function(slot, key) {
!Command.checkFlag("VALID_IN_SUBSCRIBER_MODE", command.name)
) {
command.reject(
new Error(
"Connection in subscriber mode, only subscriber commands may be used"
)
);
return command.promise;
}
var writable =
this.status === "ready" ||
(!stream &&
this.status === "connect" &&
commands.exists(command.name) &&
commands.hasFlag(command.name, "loading"));
if (!this.stream) {
writable = false;
} else if (!this.stream.writable) {
writable = false;
} else if (this.stream._writableState && this.stream._writableState.ended) {
// https://github.com/iojs/io.js/pull/1217
writable = false;
}
if (!writable && !this.options.enableOfflineQueue) {
command.reject(
new Error(
"Stream isn't writeable and enableOfflineQueue options is false"
)
);
return command.promise;
}
if (error) {
if (command.name === 'exec' && error.message === 'EXECABORT Transaction discarded because of previous errors.') {
continue;
}
if (!commonError) {
commonError = {
name: error.name,
message: error.message
};
} else if (commonError.name !== error.name || commonError.message !== error.message) {
retriable = false;
break;
}
} else if (!inTransaction) {
var isReadOnly = commands.exists(command.name) && commands.hasFlag(command.name, 'readonly');
if (!isReadOnly) {
retriable = false;
break;
}
}
}
if (commonError && retriable) {
var _this = this;
var errv = commonError.message.split(' ');
var queue = this._queue;
inTransaction = false;
this._queue = [];
for (i = 0; i < queue.length; ++i) {
if (errv[0] === 'ASK' && !inTransaction &&
queue[i].name !== 'asking' &&
(!queue[i - 1] || queue[i - 1].name !== 'asking')) {
}
if (!commonError) {
commonError = {
name: error.name,
message: error.message
};
} else if (
commonError.name !== error.name ||
commonError.message !== error.message
) {
retriable = false;
break;
}
} else if (!inTransaction) {
var isReadOnly =
exists(command.name) && hasFlag(command.name, "readonly");
if (!isReadOnly) {
retriable = false;
break;
}
}
}
if (commonError && retriable) {
var _this = this;
var errv = commonError.message.split(" ");
var queue = this._queue;
inTransaction = false;
this._queue = [];
for (let i = 0; i < queue.length; ++i) {
if (
errv[0] === "ASK" &&
!inTransaction &&
Cluster.prototype.sendCommand = function (command, stream, node) {
if (this.status === 'wait') {
this.connect().catch(_.noop);
}
if (this.status === 'end') {
command.reject(new Error(utils.CONNECTION_CLOSED_ERROR_MSG));
return command.promise;
}
var to = this.options.scaleReads;
if (to !== 'master') {
var isCommandReadOnly = commands.exists(command.name) && commands.hasFlag(command.name, 'readonly');
if (!isCommandReadOnly) {
to = 'master';
}
}
var targetSlot = node ? node.slot : command.getSlot();
var ttl = {};
var _this = this;
if (!node && !command.__is_reject_overwritten) {
command.__is_reject_overwritten = true;
var reject = command.reject;
command.reject = function (err) {
var partialTry = _.partial(tryConnection, true);
_this.handleError(err, ttl, {
moved: function (slot, key) {
debug('command %s is moved to %s', command.name, key);
Cluster.prototype.sendCommand = function (command, stream, node) {
if (this.status === 'wait') {
this.connect().catch(_.noop);
}
if (this.status === 'end') {
command.reject(new Error(utils.CONNECTION_CLOSED_ERROR_MSG));
return command.promise;
}
var to = this.options.scaleReads;
if (to !== 'master') {
var isCommandReadOnly = commands.exists(command.name) && commands.hasFlag(command.name, 'readonly');
if (!isCommandReadOnly) {
to = 'master';
}
}
var targetSlot = node ? node.slot : command.getSlot();
var ttl = {};
var _this = this;
if (!node && !command.__is_reject_overwritten) {
command.__is_reject_overwritten = true;
var reject = command.reject;
command.reject = function (err) {
var partialTry = _.partial(tryConnection, true);
_this.handleError(err, ttl, {
moved: function (slot, key) {
debug('command %s is moved to %s', command.name, key);