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
[Service Bus] Bug Fix: Unexpected expiresAtUtc: Invalid Date
in the receivedMessage
#13543
Conversation
This pull request is protected by Check Enforcer. What is Check Enforcer?Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass. Why am I getting this message?You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged. What should I do now?If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows: What if I am onboarding a new service?Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment: |
expiresAtUtc: Invalid Date
in the receivedMessage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall strategy looks good, but had some questions.
deadLetterReason: sbmsg.applicationProperties?.DeadLetterReason as string, | ||
deadLetterErrorDescription: sbmsg.applicationProperties?.DeadLetterErrorDescription as string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to add as string
? Couldn't these be undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, undefined is allowed.
…to harshan/sb/issue/12883
…to harshan/sb/issue/12883
@@ -1,5 +1,9 @@ | |||
# Release History | |||
|
|||
## 7.1.0-beta.2 (2021-04-07) | |||
|
|||
- [Bug Fix] `expiresAtUtc` is `Invalid Date` in the received message when the ttl is not defined. Has been fixed in [#13543](https://github.com/Azure/azure-sdk-for-js/pull/13543) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note, I have another PR where I'm just removing the date for .beta.1 since we never released it. So your changes would actually go there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, forgot!
} else { | ||
props.expiresAtUtc = new Date(props.enqueuedTimeUtc.getTime() + msg.ttl!); | ||
if (msg.ttl == null) msg.ttl = Constants.maxDurationValue; | ||
if (props.enqueuedTimeUtc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is props.enqueuedTime ever not set if a message has been received from an actual broker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't seen such a case, but this gives the flexibility to set the props properly even if the service messes up.
props.expiresAtUtc = new Date(props.enqueuedTimeUtc.getTime() + msg.ttl!); | ||
if (msg.ttl == null) msg.ttl = Constants.maxDurationValue; | ||
if (props.enqueuedTimeUtc) { | ||
if (msg.ttl >= Constants.maxDurationValue - props.enqueuedTimeUtc.getTime()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(is this the same?)
props.expiresAtUtc = Math.min(props.enqueuedTimeUtc.getTime() + msg.ttl, Constants.maxDurationValue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
props.expiresAtUtc = new Date(Math.min(props.enqueuedTimeUtc.getTime() + msg.ttl, Constants.maxDurationValue));
@@ -599,8 +606,10 @@ export function fromRheaMessage( | |||
: undefined, | |||
...sbmsg, | |||
...props, | |||
deadLetterReason: sbmsg.applicationProperties?.DeadLetterReason, | |||
deadLetterErrorDescription: sbmsg.applicationProperties?.DeadLetterErrorDescription | |||
deadLetterReason: sbmsg.applicationProperties?.DeadLetterReason as string | undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are on a type-roll! ;)
@@ -0,0 +1,41 @@ | |||
// Copyright (c) Microsoft Corporation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are perfect unit tests - can you move this into internal/unit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, glad you were able to remove yet one more spot where we didn't have typings :)
Hello @HarshaNalluru! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
… receivedMessage (Azure#13543) Fixes Azure#12883 ## Bug "Invalid date" for the `expiresAtUtc` property ``` azure:service-bus:messages:verbose AmqpMessage to ServiceBusReceivedMessage: { _amqpAnnotatedMessage: { header: { deliveryCount: 0 }, . . . expiresAtUtc: Invalid Date, . . . } ``` ## Background "ttl" on the received message will be undefined if the sent message doesn't have the "ttl" property set to a value. In this case, the service assumes the default infinite value for expiry time. Reference: https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-expiration#entity-level-expiration ### Cause (expiresAtUtc) In the SDK, for a received message, we calculate the expiresAtUtc using the "ttl" and the enqueued time. - If the msg.ttl > max_duration - msg.enqueuedTime, calculate msg.expiresAtUtc with max_duration - If the msg.ttl < max_duration - msg.enqueuedTime, calculate msg.expiresAtUtc with msg.enqueuedTime + msg.ttl - If the msg.ttl is not defined on the received message, we return Invalid Date for the expiresAtUtc property. ## .NET SDK TTL is defaulted to TimeSpan.MaxValue in .NET. For ExpiresAt calculation: - if AbsoluteExpiryTime is populated we use that. - if TTL > maxDateTime - EnqueuedTime, use TimeSpan.MaxValue - Else use EnqueuedTime + TTL ## Fix for JS SDK If the msg.ttl is not defined, set it to the max value as the service says that. This allows the proper calculation of `expiresAtUtc`. ## TODO - [x] Bug Fix - [x] Test - [x] Changelog
Fixes #12883
Bug
"Invalid date" for the
expiresAtUtc
propertyBackground
"ttl" on the received message will be undefined if the sent message doesn't have the "ttl" property set to a value.
In this case, the service assumes the default infinite value for expiry time.
Reference: https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-expiration#entity-level-expiration
Cause (expiresAtUtc)
In the SDK, for a received message, we calculate the expiresAtUtc using the "ttl" and the enqueued time.
.NET SDK
TTL is defaulted to TimeSpan.MaxValue in .NET.
For ExpiresAt calculation:
Fix for JS SDK
If the msg.ttl is not defined, set it to the max value as the service says that. This allows the proper calculation of
expiresAtUtc
.TODO