TwitchDropsMiner: RuntimeError: await wasn't used with future

After running for a while, the miner usually throws an error and terminates. When I try to run it again, it throws it on startup. It typically works the next day again. I’ll update this if I can figure out the circumstances more precisely.

Fatal error encountered:

Traceback (most recent call last):
  File "main.py", line 178, in <module>
  File "asyncio\base_events.py", line 646, in run_until_complete
  File "twitch.py", line 670, in run
  File "twitch.py", line 712, in _run
  File "twitch.py", line 1417, in fetch_inventory
  File "gui.py", line 1247, in add_campaign
  File "cache.py", line 97, in get
  File "contextlib.py", line 199, in __aenter__
  File "twitch.py", line 1258, in request
  File "gui.py", line 1861, in coro_unless_closed
  File "aiohttp\client.py", line 1125, in send
  File "aiohttp\client.py", line 536, in _request
  File "aiohttp\connector.py", line 540, in connect
  File "aiohttp\connector.py", line 901, in _create_connection
  File "aiohttp\connector.py", line 1175, in _create_direct_connection
  File "aiohttp\connector.py", line 980, in _wrap_create_connection
  File "asyncio\base_events.py", line 1049, in create_connection
  File "asyncio\base_events.py", line 960, in _connect_sock
  File "asyncio\proactor_events.py", line 705, in sock_connect
RuntimeError: await wasn't used with future

Exiting...

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 51 (27 by maintainers)

Most upvoted comments

I can reproduce this 10/10 times on Linux by exporting the following environment variable before running the app:

$ export SSL_CERT_FILE=/dev/null
$ python main.py

Error in the GUI:

image

I obviously understand that by doing this I’m possibly breaking libssl, and also that this problem is not exclusive to Linux.

However, since the error I’m getting seems to match the ones being reported here by other people, I thought this could be useful to figure out the root cause of the problem or something… 🤷

Recent activity under https://github.com/aio-libs/aiohttp/issues/7117 suggests it could be caused by an asynchronous object somehow getting created before a new default loop is set. This causes a mismatched loop and this error. The thing is, it’s not consistent - it appears to depend on a specific machine. Both Windows and Linux are affected, but for ex. I can’t reproduce it, beyond a single, singular time it happened to me a long time ago during development, and then never again. Without being able to repro it myself, I can’t test any solutions in an efficient manner. It can be related to anything, including OS version, Python version, specific hardware and drivers being installed, etc. Nobody will know until the linked aiohtttp issue resolves.

Just in case - I am still interested in confirmation that it’s really help for your case.

Actually, nevermind - the PR has already been merged (https://github.com/aio-libs/aiohttp/commit/a57dc3146839e2e1978b96db48e1de3af1a2bb50), and it looks like the fix will become available in v3.9 of aiohttp. According to https://github.com/aio-libs/aiohttp/issues/7675, it’s currently in beta testing, soon nearing official release. Once it is released, I’ll update requirements.txt to require v3.9 of aiohttp specifically, and that should finally close this issue.

Okay, so I have some good news. There’s been a PR made to aiohttp, that supposedly fixes this issue. In order to confirm that it works, I’d need someone who experiences this issue, to install the PR fix into the env folder with:

pip install --force-reinstall git+https://github.com/stalkerg/aiohttp@coroutine-wrapper-fix

If you’d be unsure how to do this, you can change the requirements.txt file’s first line of aiohttp>2.0,<4.0 to:

aiohttp@git+https://github.com/stalkerg/aiohttp@coroutine-wrapper-fix

…, and then delete and recreate the env folder by running setup_env.bat again. After that, just run the application from source and see if the issue is still present.

PR link: https://github.com/aio-libs/aiohttp/pull/7785

@guihkx Could you try running your repro on this piece of code, if possible?

import asyncio
import aiohttp

async def main():
    async with aiohttp.request("https://google.com") as response:
       print(await response.text())

asyncio.run(main())

Since this issue now received an official CPython issue and has a repro, I’d like to find something smaller than this entire monster of a project, to repro the issue on. If you’d happen to have a Discord account (or would be willing to make one), we could sit down tomorrow, around 2-6 PM your time (assuming GMT-3), to hopefully narrow it down as much as possible. Well, unless it already fails on the code above x) I’d prefer Discord as it makes it easier to discuss things over interactive chat, rather than messages under issues like this one.

My Discord tag is DevilXD#4437, or simply devilxd with this new naming system Discord introduced recently.

An interesting find. This information should probably be put under the aiohttp issue for sure. I’ll pass it there.

I’m running the compiled version, so I ran the commands in the folder I used to build the exe. Python 3.10.6 Win 10 22H2 (build 19045.2251)

Name: aiohttp
Version: 3.8.3
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Location: c:\users\arne\onedrive\desktop\building_tdminer\twitchdropsminer\env\lib\site-packages
Requires: aiosignal, async-timeout, attrs, charset-normalizer, frozenlist, multidict, yarl
Required-by:
Name: multidict
Version: 6.0.2
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: c:\users\arne\onedrive\desktop\building_tdminer\twitchdropsminer\env\lib\site-packages
Requires:
Required-by: aiohttp, yarl
Name: yarl
Version: 1.8.1
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: c:\users\arne\onedrive\desktop\building_tdminer\twitchdropsminer\env\lib\site-packages
Requires: idna, multidict
Required-by: aiohttp

I’ll try 5e53448 and let you know if I encounter it again.