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] Use AwaitableSender in lieu of Sender #4446

Merged
merged 25 commits into from
Aug 2, 2019

Conversation

ramya0820
Copy link
Member

For more context refer to #3375

@chradek
Copy link
Contributor

chradek commented Jul 26, 2019

I think you need to update the version of rhea-promise to make use of the AwaitableSender. Currently seeing builds failures because the type is missing.

@ramya0820
Copy link
Member Author

ramya0820 commented Jul 26, 2019

I think you need to update the version of rhea-promise to make use of the AwaitableSender. Currently seeing builds failures because the type is missing.

Discussed offline about this - the version update is part of #4228 and so changes/merge from master would fix the build errors (after which current PR can be merged).

PR and code cannot be checked in anyway without build passing, hoping any concerns about the main issue, problem can be reviewed and surfaced as part of the review.

Other than that, please see linked issue thread - #3375 (comment)
The changes were successfully built on local, run and tested.

}

onAborted = () => {
removeListeners();
rejectOnAbort();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to add a return here or else the function will continue running.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rejectOnAbort has a return reject(..) in it, would we still need another return here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. rejectOnAbort is a function. The return in it only returns from that function and not the outer code set of {}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated..

Copy link
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The per try timeout configured by the user is being used only for link creation and not the actual sending of the message

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jul 30, 2019

Hmm.. I see the discussion in #3375 (comment) and understand the trouble behind sharing the timeout value between link creation and actual sending of the message.

This would need some changes in rhea-promise.
But for now, for the sake of this PR, lets pass the per try timeout set by the user as part of the options used to create the sender i.e set the sendTimeoutInSeconds option.

For send operations by the user where the sender is already created, this will result in exactly what we want.

For send operations by the user where the sender is not yet created, this will end up in doubling the net timeout. We can fix this once amqp/rhea-promise#49 is fixed.

* Checks if given object maps to a valid custom error. If yes, configures and returns the appropriate error instance, else returns `undefined`.
* @param err
*/
function getCustomError(err: AmqpError | Error): MessagingError | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to cover any of the amqp errors here because amqp errors should undergo the appropriate processing as covered in the translate(). Therefore, make an early exit from here if isAmqpError(err) returns true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we have updated the if/else in translate() to use the result of this method only when it is not an amqp error. That is good.
But here since the input supports both AmqpError and simple Error, it is still confusing to anyone reading this code independently

My first suggestion would have been to update this method to take in only Error, but this might not work out due to typing issues. Because as far as the typescript compiler is concerned, the err object you pass in could be either of the 2 types.

Please consider not having this as a separate method and moving the code here directly into translate()

Copy link
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from #4446 (comment), the errors.ts file needs some work.

Other than looking good. Let's try to wrap this up tomorrow after a merge from the master branch

@@ -622,6 +639,8 @@ export function translate(err: AmqpError | Error): MessagingError {
error = new MessagingError("Websocket connection failed.");
error.name = ConditionErrorNameMapper[ErrorNameConditionMapper.ServiceCommunicationError];
error.retryable = false;
} else if (customError) {
return customError;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are creating the custom error up front and using it only after a series of if/elses, the current model slightly hurts code readability and the ease of understanding.

I would suggest the below

if (isAmqpError(err)) { // do the needful and return the error }
if (isSystemError(err)) { // do the needful and return the error }
if (isBrowserWebsocketError(err)) { // do the needful and return the error }
const customError = getCustomError(err)
if (customError) {
   return customError
}
// The generic error handling here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take another look at the suggested code change above.
Apart from moving the call to getCustomError(), the suggestion was to add return the error from each of the if blocks and avoiding the else blocks.

With f5f0428, you have moved the call to getCustomError and removed the else but are not returning the error object from the previous if blocks.

Due to this regardless of all the processing that is done by if (isAmqpError(err)), if (isSystemError(err)) and if (isBrowserWebsocketError(err)) all the non custom errors are getting converted to a generic error. This is also the reason why the tests are failing

Copy link
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newName: true
});
const options: AwaitableSenderOptions = this._createSenderOptions(
Constants.defaultOperationTimeoutInMs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we want to recreate the sender link with new name, therefore in the old code we used to pass newName: true to _createSenderOptions

In the updated code, we are no longer asking this. _createSenderOptions to use the new name

@@ -682,13 +606,12 @@ export class EventHubSender extends LinkEntity {

try {
await defaultLock.acquire(this.senderLock, () => {
return this._init();
return this._init(
this._createSenderOptions(getRetryAttemptTimeoutInMs(options.retryOptions))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feedback at #4446 (comment) to avoid inlining applies here as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants