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

aiohttp Too long request causes InvalidStateError #78

Open
Rybak5611 opened this issue Aug 30, 2017 · 2 comments
Open

aiohttp Too long request causes InvalidStateError #78

Rybak5611 opened this issue Aug 30, 2017 · 2 comments

Comments

@Rybak5611
Copy link

Rybak5611 commented Aug 30, 2017

Mysterious crash when aiohttp.request takes too much time to execute ( ~2-3 sec ).
In my case it happens almost everytime when i make request to twitch.tv.
Doesn't seem to be aiohttp-only issue as it only happens with quamash loop.

import asyncio
import aiohttp
import sys
import quamash
import PyQt5
import PyQt5.QtWidgets

class Window( PyQt5.QtWidgets.QWidget ):

	def __init__( self ):

		super( ).__init__()

		self.resize( 200, 200 )
		self.setWindowTitle( "Test" )

		Layout = PyQt5.QtWidgets.QVBoxLayout()

		Button = PyQt5.QtWidgets.QPushButton( "Get twitch.tv ( crash )" )
		Button.clicked.connect( lambda: asyncio.Task( self.aRequest( "http://twitch.tv/" ), loop=Loop ) ) 
		Layout.addWidget( Button )

		Button = PyQt5.QtWidgets.QPushButton( "Get google.com" )
		Button.clicked.connect( lambda: asyncio.Task( self.aRequest( "http://google.com/" ), loop=Loop ) ) 
		Layout.addWidget( Button )

		self.setLayout( Layout )

		self.show()

	async def aRequest( self, URL ):
		Response = await aiohttp.request( "GET", URL, loop=Loop )

if __name__ == "__main__":
	
	Application = PyQt5.QtWidgets.QApplication( sys.argv )
	Loop = quamash.QEventLoop( Application )
	asyncio.set_event_loop( Loop )

	_ = Window()

	with Loop:
		Loop.run_forever()
>test.py
Traceback (most recent call last):
  File "C:\Py36\lib\site-packages\quamash\_windows.py", line 46, in _process_events
    f.set_result(value)
  File "C:\Py36\lib\asyncio\windows_events.py", line 83, in set_result
    super().set_result(result)
asyncio.base_futures.InvalidStateError: invalid state

Windows==10.0.15063
Python==3.6
PyQt5==5.9
aiohttp>=2.0.3
quamash==0.5.5

@asvetlov

@Rybak5611 Rybak5611 changed the title aiohttp twitch.tv InvalidStateError aiohttp Too long request causes InvalidStateError Aug 30, 2017
@asvetlov
Copy link

Personally I see nothing special for aiohttp itself.
Would you provide more details?
Full stacktrace and future's current state could help.

@TheRandomDog
Copy link

TheRandomDog commented Apr 16, 2018

So I'm not really keen on committing to more "low-level" (yeah, it's probably not that low :P) stuff because I don't have a full understanding of what's going on, but I found something that seems to work for me without causing troubles.

I noticed for some reason that quamash was getting the same Future instance twice and trying to set it as done twice... which as the documentation notes, raises the InvalidStateError in question. To avoid this problem, I simply added a check to see if the future was already marked as complete where the error occurs.

if not f.done():
    f.set_result(value)

Now I'm not trying to be dogmatic about this fix here, it just worked for me and I was trying something quick and easy. It might be a bigger problem that quamash is receiving and trying to mark the same Future as complete twice, or that ignoring the second send of the Future may end up being problematic. But hey, if you're looking for a quick fix in the meantime! Maybe someone more experienced can give better insight into the issue, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants