Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

pubsub.get_message(blocking_timeout) don't work with async_timeout.timeout #1424

Open
@heyfavour

Description

@heyfavour

Describe the bug

await pubsub.subscribe(self.channel)
try:
    start_time = datetime.datetime.now()
    async with async_timeout.timeout(blocking_timeout):
        while True:
            message = await pubsub.get_message(ignore_subscribe_messages=True, timeout=blocking_timeout)
            end_time = datetime.datetime.now()
            logger.info(f"{str(message)},{blocking_timeout}==={end_time-start_time}")
            if message is not None: break
except asyncio.TimeoutError:
    pass

i set get_message's blocking_timeout equals async_timeout 's blocking_timeout
but i found when they are similar or equal , async_timeout.timeout will not works it will always run util get a message

To Reproduce

python=3.10.2
aioredis=2.10.1
async-timeout = 4.0.2
mycode

Expected behavior

catch timeouterror

Logs/tracebacks

2022-09-27 14:42:21,621 - 269 - [0]cust_no:product_no0:89e4caf93e2f11ed94e1484d7ecf8cb7
2022-09-27 14:42:21,622 - 269 - [1]cust_no:product_no1:89e4f2063e2f11edab66484d7ecf8cb7
2022-09-27 14:42:21,623 - 269 - [2]cust_no:product_no0:89e5191b3e2f11edba6c484d7ecf8cb7
2022-09-27 14:42:21,647 - 273 - [0] cust_no:product_no0 True {'89e4caf93e2f11ed94e1484d7ecf8cb7': '1'} 第一次获取锁
2022-09-27 14:42:21,651 - 273 - [1] cust_no:product_no1 True {'89e4f2063e2f11edab66484d7ecf8cb7': '1'} 第一次获取锁
2022-09-27 14:42:21,653 - 185 - None,3===0:00:00.007000
2022-09-27 14:42:21,662 - 258 - [0] cust_no:product_no0 True {'89e4caf93e2f11ed94e1484d7ecf8cb7': '2'} 第二次获取锁
2022-09-27 14:42:21,667 - 258 - [1] cust_no:product_no1 True {'89e4f2063e2f11edab66484d7ecf8cb7': '2'} 第二次获取锁
2022-09-27 14:42:24,657 - 185 - None,3===0:00:03.012440
2022-09-27 14:42:24,664 - 260 - [0] sleep ---> key:{'89e4caf93e2f11ed94e1484d7ecf8cb7': '2'} 第二次锁后sleep
2022-09-27 14:42:24,664 - 260 - [1] sleep ---> key:{'89e4f2063e2f11edab66484d7ecf8cb7': '2'} 第二次锁后sleep
2022-09-27 14:42:24,677 - 262 - [0] cust_no:product_no0_release2:2 {'89e4caf93e2f11ed94e1484d7ecf8cb7': '1'} 释放第二次锁
2022-09-27 14:42:24,678 - 262 - [1] cust_no:product_no1_release2:2 {'89e4f2063e2f11edab66484d7ecf8cb7': '1'} 释放第二次锁
2022-09-27 14:42:27,675 - 185 - None,3===0:00:06.030194
2022-09-27 14:42:27,682 - 276 - [0] keycust_no:product_no0 ttl:26990 查看剩余时间
2022-09-27 14:42:27,683 - 276 - [1] keycust_no:product_no1 ttl:26989 查看剩余时间
2022-09-27 14:42:27,695 - 278 - [0] keycust_no:product_no0 ttl:36977 续命
2022-09-27 14:42:27,696 - 278 - [1] keycust_no:product_no1 ttl:36976 续命
2022-09-27 14:42:27,702 - 185 - {'type': 'message', 'pattern': None, 'channel': 'redisson_lock_channel:cust_no:product_no0', 'data': '89e4caf93e2f11ed94e1484d7ecf8cb7'},3===0:00:06.057626
2022-09-27 14:42:29,720 - 281 - [0] cust_no:product_no0_release1:1 {} 释放第一次锁
2022-09-27 14:42:29,728 - 281 - [1] cust_no:product_no1_release1:1 {} 释放第一次锁
2022-09-27 14:42:29,740 - 273 - [2] cust_no:product_no0 True {'89e5191b3e2f11edba6c484d7ecf8cb7': '1'} 第一次获取锁
2022-09-27 14:42:29,757 - 258 - [2] cust_no:product_no0 True {'89e5191b3e2f11edba6c484d7ecf8cb7': '2'} 第二次获取锁
2022-09-27 14:42:32,775 - 260 - [2] sleep ---> key:{'89e5191b3e2f11edba6c484d7ecf8cb7': '2'} 第二次锁后sleep
2022-09-27 14:42:32,789 - 262 - [2] cust_no:product_no0_release2:2 {'89e5191b3e2f11edba6c484d7ecf8cb7': '1'} 释放第二次锁

Python Version

3.10.2

aioredis Version

4.0.2

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions