Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// the Promise is rejected. The "microsoft.timeout" error occurs when timeout happens on
// the server side and ServiceBus sends a detach frame due to which the Promise is rejected.
if (
err.name === ConditionErrorNameMapper["amqp:operation-timeout"] ||
err.name === ConditionErrorNameMapper["com.microsoft:timeout"] ||
err.name === ConditionErrorNameMapper["com.microsoft:session-cannot-be-locked"]
) {
// No point in delaying if cancel has been requested.
if (!this._isCancelRequested) {
log.sessionManager(
"[%s] Sleeping for %d seconds, since there are no more active MessageSessions on " +
"the ServiceBus entity.",
connectionId,
noActiveSessionBackOffInSeconds
);
await delay(noActiveSessionBackOffInSeconds * 1000);
}
} else {
// notify the user about the error only when it is not one of the above mentioned errors.
onError(err);
}
} finally {
this._maxPendingAcceptSessionsSemaphore.release();
log.sessionManager(
"[%s] Releasing the semaphore for max pending accept sessions from " +
"the finally block: %d, %d.",
connectionId,
this._maxPendingAcceptSessionsSemaphore.currentLockCount(),
this._maxPendingAcceptSessionsSemaphore.awaitedTaskCount()
);
}
}const clientContext = connectionContext.clientContexts[id];
if (clientContext.managementClient) {
await clientContext.managementClient.close();
}
}
// The connection should always be brought back up if the sdk did not call connection.close()
// and there was atleast one sender/receiver link on the connection before it went down.
log.error("[%s] state: %O", connectionContext.connectionId, state);
if (!state.wasConnectionCloseCalled && state.numClients) {
log.error(
"[%s] connection.close() was not called from the sdk and there were some " +
"clients. We should reconnect.",
connectionContext.connection.id
);
await delay(Constants.connectionReconnectDelay);
// reconnect clients if any
for (const id of Object.keys(connectionContext.clientContexts)) {
const clientContext = connectionContext.clientContexts[id];
log.error(
"[%s] calling detached on client '%s'.",
connectionContext.connection.id,
clientContext.clientId
);
clientContext.onDetached(connectionError || contextError).catch((err) => {
log.error(
"[%s] An error occurred while reconnecting the sender '%s': %O.",
connectionContext.connection.id,
clientContext.clientId,
err
);
});let waitTimer: any;
log.sender(
"[%s] Sender '%s', credit: %d available: %d",
this._context.namespace.connectionId,
this.name,
this._sender!.credit,
this._sender!.session.outgoing.available()
);
if (!this._sender!.sendable()) {
log.sender(
"[%s] Sender '%s', waiting for 1 second for sender to become sendable",
this._context.namespace.connectionId,
this.name
);
await delay(1000);
log.sender(
"[%s] Sender '%s' after waiting for a second, credit: %d available: %d",
this._context.namespace.connectionId,
this.name,
this._sender!.credit,
this._sender!.session.outgoing.available()
);
}
if (this._sender!.sendable()) {
let onRejected: Func;
let onReleased: Func;
let onModified: Func;
let onAccepted: Func;
const removeListeners = (): void => {
clearTimeout(waitTimer);private async _collectExpiredEntries(): Promise {
if (this._map.size === 0) {
return;
}
await delay(this._delayBetweenCleanupInSeconds);
this._cleanupScheduled = false;
for (const key of this._map.keys()) {
if (Date.now() > this._map.get(key)!.getTime()) {
this._map.delete(key);
log.map("Deleted the key '%s' from the map.", key);
}
}
this._scheduleCleanup().catch((err) => {
log.error(
"An error occurred while scheduling the cleanup, after " + "collecting expired entries: %O",
err
);
});
}