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

[ServiceBus] Fix mktime overflow and milliseconds miscalculation issue #19437

Merged
merged 3 commits into from
Jun 29, 2021
Merged
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
8 changes: 6 additions & 2 deletions sdk/servicebus/azure-servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## 7.3.1 (Unreleased)

**Bug Fixes**
### Fixed

* Fixed a bug that when setting `ServiceBusMessage.partition_key`, input value should be not validated against `session_id` of None (PR #19233, thanks @bishnu-shb).
- Fixed a bug that when setting `ServiceBusMessage.partition_key`, input value should be not validated against `session_id` of None (PR #19233, thanks @bishnu-shb).
- Fixed a bug that setting `ServiceBusMessage.time_to_live` causes OverflowError error on Ubuntu 20.04.
- Fixed a bug that `AmqpAnnotatedProperties.creation_time` and `AmqpAnnotatedProperties.absolute_expiry_time` should be calculated in the unit of milliseconds instead of seconds.
- Updated uAMQP dependency to 1.4.1.
- Fixed a bug that attributes creation_time, absolute_expiry_time and group_sequence on MessageProperties should be compatible with integer types on Python 2.7.

## 7.3.0 (2021-06-08)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def time_to_live(self, value):
self._raw_amqp_message.header.time_to_live != MAX_DURATION_VALUE:
if not self._raw_amqp_message.properties:
self._raw_amqp_message.properties = AmqpMessageProperties()
self._raw_amqp_message.properties.creation_time = int(time.mktime(utc_now().timetuple()))
self._raw_amqp_message.properties.creation_time = int(time.mktime(utc_now().timetuple())) * 1000
self._raw_amqp_message.properties.absolute_expiry_time = min(
MAX_ABSOLUTE_EXPIRY_TIME,
self._raw_amqp_message.properties.creation_time + self._raw_amqp_message.header.time_to_live
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
cast
)
from contextlib import contextmanager
from msrest.serialization import UTC
from msrest.serialization import TZ_UTC

try:
from urlparse import urlparse
Expand Down Expand Up @@ -81,11 +81,11 @@


def utc_from_timestamp(timestamp):
return datetime.datetime.fromtimestamp(timestamp, tz=UTC())
return datetime.datetime.fromtimestamp(timestamp, tz=TZ_UTC)


def utc_now():
return datetime.datetime.now(UTC())
return datetime.datetime.now(TZ_UTC)


def build_uri(address, entity):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import datetime
from typing import Optional, Any, cast, Mapping

from msrest.serialization import UTC
from msrest.serialization import TZ_UTC
import uamqp

from ._constants import AMQP_MESSAGE_BODY_TYPE_MAP, AmqpMessageBodyType
Expand Down Expand Up @@ -229,7 +229,7 @@ def _to_outgoing_amqp_message(self):
message_header.priority = self.header.priority
if self.header.time_to_live and self.header.time_to_live != MAX_DURATION_VALUE:
ttl_set = True
creation_time_from_ttl = int(time.mktime(datetime.now(UTC()).timetuple()))
creation_time_from_ttl = int(time.mktime(datetime.now(TZ_UTC).timetuple()) * 1000)
absolute_expiry_time_from_ttl = int(min(
MAX_ABSOLUTE_EXPIRY_TIME,
creation_time_from_ttl + self.header.time_to_live
Expand Down
2 changes: 1 addition & 1 deletion sdk/servicebus/azure-servicebus/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
'azure',
]),
install_requires=[
"uamqp>=1.4.0,<2.0.0",
"uamqp>=1.4.1,<2.0.0",
'azure-common~=1.1',
'msrest>=0.6.17,<2.0.0',
'azure-core<2.0.0,>=1.14.0',
Expand Down
2 changes: 1 addition & 1 deletion shared_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ opentelemetry-sdk<2.0.0,>=1.0.0
#override azure-eventhub uamqp>=1.4.0,<2.0.0
#override azure-appconfiguration msrest>=0.6.10
#override azure-mgmt-appconfiguration msrest>=0.6.21
#override azure-servicebus uamqp>=1.4.0,<2.0.0
#override azure-servicebus uamqp>=1.4.1,<2.0.0
#override azure-servicebus msrest>=0.6.17,<2.0.0
#override azure-servicebus azure-core<2.0.0,>=1.14.0
#override azure-servicefabric msrest>=0.6.21
Expand Down