Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Hubs] [core-amqp] Update retry operation scope for Management Requests #4321

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sdk/core/core-amqp/src/requestResponseLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ export class RequestResponseLink implements ReqResLink {
};

this.receiver.on(ReceiverEvents.message, messageCallback);
waitTimer = setTimeout(actionAfterTimeout, options!.timeoutInSeconds! * 1000);
if (options && options.timeoutInSeconds && options!.timeoutInSeconds > 0) {
waitTimer = setTimeout(actionAfterTimeout, options!.timeoutInSeconds! * 1000);
}
log.reqres(
"[%s] %s request sent: %O",
this.connection.id,
Expand Down
95 changes: 64 additions & 31 deletions sdk/eventhub/event-hubs/src/managementClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import {
defaultLock,
translate,
Constants,
SendRequestOptions
retry,
RetryConfig,
RetryOperationType,
SendRequestOptions,
randomNumberFromInterval
} from "@azure/core-amqp";

import {
Message,
Message as AmqpMessage,
EventContext,
SenderEvents,
ReceiverEvents,
Expand Down Expand Up @@ -305,37 +310,65 @@ export class ManagementClient extends LinkEntity {
request: Message,
options?: { retryOptions?: RetryOptions; abortSignal?: AbortSignalLike; requestName?: string }
): Promise<any> {
try {
log.mgmt(
"[%s] Acquiring lock to get the management req res link.",
this._context.connectionId
);
await defaultLock.acquire(this.managementLock, () => {
return this._init();
});
if (!options) options = {};

if (!options) {
options = {};
}
const sendOperationPromise = () =>
new Promise<void>((resolve, reject) => {
const rejectOnSendError = (err: Error) => {
err = translate(err);
log.error("An error occurred while making the request to $management endpoint: %O", err);
reject(err);
};

const sendRequestOptions: SendRequestOptions = {
maxRetries: options.retryOptions && options.retryOptions.maxRetries,
abortSignal: options.abortSignal,
requestName: options.requestName,
timeoutInSeconds: getRetryAttemptTimeoutInMs(options.retryOptions) / 1000,
delayInSeconds:
options.retryOptions &&
options.retryOptions.retryInterval &&
options.retryOptions.retryInterval >= 0
? options.retryOptions.retryInterval / 1000
: undefined
};
return (await this._mgmtReqResLink!.sendRequest(request, sendRequestOptions)).body;
} catch (err) {
err = translate(err);
log.error("An error occurred while making the request to $management endpoint: %O", err);
throw err;
}
log.mgmt(
"[%s] Acquiring lock to get the management req res link.",
this._context.connectionId
);

defaultLock
.acquire(this.managementLock, () => {
return this._init();
})
.then(() => {
const sendRequestOptions: SendRequestOptions = {
abortSignal: options!.abortSignal,
requestName: options!.requestName,

// Following config values ensure "retry" is disabled
// i.e., operation is attempted just once and timers on it within the utility are not created
maxRetries: 0,
timeoutInSeconds: -1,
delayInSeconds: 0
};
this._mgmtReqResLink!.sendRequest(request, sendRequestOptions)
.then((message: AmqpMessage) => {
resolve(message);
})
.catch((err: Error) => {
rejectOnSendError(err);
});
})
.catch((err: Error) => {
rejectOnSendError(err);
});
});

const jitterInSeconds = randomNumberFromInterval(1, 4);
const maxRetries = options.retryOptions && options.retryOptions.maxRetries;
const delayInSeconds =
options.retryOptions &&
options.retryOptions.retryInterval &&
options.retryOptions.retryInterval >= 0
? options.retryOptions.retryInterval / 1000
: Constants.defaultDelayBetweenOperationRetriesInSeconds;
const config: RetryConfig<void> = {
operation: sendOperationPromise,
connectionId: this._context.connectionId,
operationType: RetryOperationType.sendMessage,
maxRetries: maxRetries,
delayInSeconds: delayInSeconds + jitterInSeconds
};
return retry<void>(config).body;
}

private _isMgmtRequestResponseLinkOpen(): boolean {
Expand Down