-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Event Hubs] Perform sendRequest() operation handling from SDK #4322
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
Changes from 13 commits
260b0e6
c74f5e4
00016cb
5876468
2f10541
934130d
a974e22
41c5f08
5b6d1e1
80624c4
ef7d712
2ebcc2f
5dec336
ebd6e13
4e31c97
776680c
4a088bc
1617865
c64168c
57f4f01
71570d9
492fe0f
c8a1887
3fb5286
e16757e
e8e5cc6
cc15d72
868fafd
df19eae
d997887
f304522
fb13acd
c149776
7e1036a
2910d8b
885ac8f
a636a13
590ece6
9008fb2
e9232ee
b7a78a1
0ba8305
c13de88
76aea7b
cd11d1c
a5988d0
6ab619e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,11 @@ import { | |
| defaultLock, | ||
| translate, | ||
| Constants, | ||
| SendRequestOptions | ||
| SendRequestOptions, | ||
| retry, | ||
| RetryConfig, | ||
| RetryOperationType, | ||
| randomNumberFromInterval | ||
| } from "@azure/core-amqp"; | ||
| import { | ||
| Message, | ||
|
|
@@ -306,31 +310,86 @@ export class ManagementClient extends LinkEntity { | |
| 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 = {}; | ||
| } | ||
|
|
||
| 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 | ||
| const sendOperationPromise = () => | ||
| new Promise<Message>(async (resolve, reject) => { | ||
| try { | ||
| const actionAfterTimeout = () => { | ||
| const address = this._mgmtReqResLink!.receiver.address || "address"; | ||
| const desc: string = | ||
| `The request with message_id "${request.message_id}" to "${address}" ` + | ||
| `endpoint timed out. Please try again later.`; | ||
| const e: Error = { | ||
| name: "OperationTimeoutError", | ||
| message: desc | ||
| }; | ||
| return reject(translate(e)); | ||
| }; | ||
|
|
||
| const waitTimer = setTimeout( | ||
| actionAfterTimeout, | ||
| getRetryAttemptTimeoutInMs(options!.retryOptions) | ||
| ); | ||
|
|
||
| const initOperationStartTime = Date.now(); | ||
| log.mgmt( | ||
| "[%s] Acquiring lock to get the management req res link.", | ||
| this._context.connectionId | ||
| ); | ||
| await defaultLock.acquire(this.managementLock, () => { | ||
|
ramya-rao-a marked this conversation as resolved.
Outdated
|
||
| return this._init().catch((err: Error) => { | ||
| clearTimeout(waitTimer); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also check if the operation was cancelled after calling _init. If it has, we know we can close the connection and reject.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This second check is unnecessary since we already have one at the start of Discussed offline about how
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree |
||
| reject(translate(err)); | ||
| }); | ||
| }); | ||
| const initOperationEndTime = Date.now(); | ||
|
|
||
|
ramya-rao-a marked this conversation as resolved.
|
||
| if (!options) { | ||
| options = {}; | ||
| } | ||
|
|
||
| const operationTimeoutInMs = initOperationEndTime - initOperationStartTime; | ||
|
ramya-rao-a marked this conversation as resolved.
Outdated
|
||
| const sendRequestOptions: SendRequestOptions = { | ||
| abortSignal: options.abortSignal, | ||
| requestName: options.requestName, | ||
| timeoutInSeconds: operationTimeoutInMs / 1000 | ||
| }; | ||
|
|
||
| const result = await this._mgmtReqResLink!.sendRequest(request, sendRequestOptions); | ||
| resolve(result); | ||
| } catch (err) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I would imagine that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It allows us to catch errors from other code paths in case any gets thrown and indicate in logs with a message about source of it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 2 points from where an error can be expected to be thrown (by code that this file doesnt control) are the |
||
| err = translate(err); | ||
| const address = this._mgmtReqResLink!.sender.address || "address"; | ||
|
ramya0820 marked this conversation as resolved.
Outdated
|
||
| log.error( | ||
| "[%s] An error occurred during send on management request-response link '%s' with address " + | ||
| "'%s': %O", | ||
| this._context.connectionId, | ||
| this._mgmtReqResLink!.name, | ||
| address, | ||
| err | ||
| ); | ||
| reject(err); | ||
| } | ||
| }); | ||
|
|
||
| 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.management, | ||
| maxRetries: maxRetries, | ||
|
ramya-rao-a marked this conversation as resolved.
|
||
| delayInSeconds: delayInSeconds | ||
| }; | ||
| return (await this._mgmtReqResLink!.sendRequest(request, sendRequestOptions)).body; | ||
| return (await retry<Message>(config)).body; | ||
| } catch (err) { | ||
| err = translate(err); | ||
| log.error("An error occurred while making the request to $management endpoint: %O", err); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.