await contact.ready() for a non-exist contact_id hangs up 300 seconds and got a GRPCError: get contact timeout
Describe the bug
When using a bot, if we load a contact with a manually given id, and then call await contact.ready() to get the contact_payload.
If the id is an actually exist wechaty user (no matter if it is a friend), the result returns as expected soon.
Otherwise (id is a non-exist user), the ready function (exactly contact.puppet.contact_payload function inside) hangs up for exactly 300 seconds, and finally throws a grpclib.exceptions.GRPCError: (<Status.,INTERNAL: 13>, 'get contact timeout', None)
In my opinion, the case when we trying to get contact_payload of a non-exists id should report an error instantiatly, rather than hanging up for such a long time.
To Reproduce
for example:
bot = Wechaty()
async def on_login(user: Contact):
from time import time
contact: Contact = Contact('non1exist1user')
ttt = time()
try:
result = await contact.ready()
print(result)
print('>>> Success, Duration', time() - ttt)
except Exception as e:
print('>>> Fail, Duration', time() - ttt)
raise e
bot.on('login', on_login)
await bot.start()
Expected behavior
If the given contact id not exist, It should raise an error soon, rather than hanging up for 300 seconds.
Screenshots
ERROR:asyncio:Exception in callback AsyncIOEventEmitter._emit_run.<locals>._callback(<Task finishe...meout', None)>) at /home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/pyee/_asyncio.py:55
handle: <Handle AsyncIOEventEmitter._emit_run.<locals>._callback(<Task finishe...meout', None)>) at /home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/pyee/_asyncio.py:55>
Traceback (most recent call last):
File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/pyee/_asyncio.py", line 62, in _callback
self.emit('error', exc)
File "/home/alfred/app/python-wechaty-getting-started/python-wechaty/src/wechaty/wechaty.py", line 255, in emit
super().emit(event, *args, **kwargs)
File "/home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/pyee/_base.py", line 111, in emit
self._emit_handle_potential_error(event, args[0] if args else None)
File "/home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/pyee/_base.py", line 83, in _emit_handle_potential_error
raise error
File "/home/alfred/app/python-wechaty-getting-started/examples/puppetware/main.py", line 52, in on_login
raise e
File "/home/alfred/app/python-wechaty-getting-started/examples/puppetware/main.py", line 47, in on_login
result = await contact.ready()
File "/home/alfred/app/python-wechaty-getting-started/python-wechaty/src/wechaty/user/contact.py", line 172, in ready
self.contact_id)
File "/home/alfred/app/python-wechaty-getting-started/python-wechaty-puppet-hostie/src/wechaty_puppet_hostie/puppet.py", line 505, in contact_payload
response = await self.puppet_stub.contact_payload(id=contact_id)
File "/home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/chatie_grpc/wechaty.py", line 723, in contact_payload
"/wechaty.Puppet/ContactPayload", request, ContactPayloadResponse,
File "/home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/betterproto/__init__.py", line 1123, in _unary_unary
response = await stream.recv_message()
File "/home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/grpclib/client.py", line 387, in recv_message
await self.recv_initial_metadata()
File "/home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/grpclib/client.py", line 355, in recv_initial_metadata
self._raise_for_grpc_status(headers_map)
File "/home/alfred/.virtualenvs/wechaty/lib/python3.7/site-packages/grpclib/client.py", line 316, in _raise_for_grpc_status
raise GRPCError(status, message, details)
grpclib.exceptions.GRPCError: (<Status.INTERNAL: 13>, 'get contact timeout', None)
Desktop (please complete the following information):
- OS: Ubuntu 18.10 (for running bot 3.7)
- Browser: Nope
- Version: wechaty==0.5.dev1 wechaty-puppet==0.0.11 wechaty-puppet-hostie==0.2.6
Smartphone (please complete the following information): Nope
Additional context It seems that the problem is caused by the puppet-hosite server. If needed, I think puppet-server maintainer will have more information about this issue.