miyakogi / pyppeteer

Headless chrome/chromium automation library (unofficial port of puppeteer)
Other
3.57k stars 371 forks source link

[BUG] Websocket sometimes get lose connection on container #259

Open xncbf opened 5 years ago

xncbf commented 5 years ago
[E:pyppeteer.connection] connection unexpectedly closed
Task exception was never retrieved
future: <Task finished coro=<Connection._async_send() done, defined at /usr/local/lib/python3.7/site-packages/pyppeteer/connection.py:69> exception=InvalidStateError('invalid state')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 795, in transfer_data
    message = await self.read_message()
  File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 863, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 938, in read_data_frame
    frame = await self.read_frame(max_size)
  File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 1018, in read_frame
    extensions=self.extensions,
  File "/usr/local/lib/python3.7/site-packages/websockets/framing.py", line 121, in read
    data = await reader(2)
  File "/usr/local/lib/python3.7/asyncio/streams.py", line 677, in readexactly
    raise IncompleteReadError(incomplete, n)
asyncio.streams.IncompleteReadError: 0 bytes read on a total of 2 expected bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pyppeteer/connection.py", line 73, in _async_send
    await self.connection.send(msg)
  File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 530, in send
    await self.ensure_open()
  File "/usr/local/lib/python3.7/site-packages/websockets/protocol.py", line 771, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pyppeteer/connection.py", line 79, in _async_send
    await self.dispose()
  File "/usr/local/lib/python3.7/site-packages/pyppeteer/connection.py", line 170, in dispose
    await self._on_close()
  File "/usr/local/lib/python3.7/site-packages/pyppeteer/connection.py", line 153, in _on_close
    f'Protocol error {cb.method}: Target closed.',  # type: ignore
asyncio.base_futures.InvalidStateError: invalid state

Above is container error logs

SinaRanjkeshzade commented 4 years ago

Hi, I have similar problem. I've used ws.send in a loop.run_until_complete and after sending some amount of data, I got this error: File "<ipython-input-1-2de4519b4e62>", line 144, in service_connection await ws.send(message) File "Local_Addr\lib\site-packages\websockets\protocol.py", line 530, in send await self.ensure_open() File "Local_Addr\lib\site-packages\websockets\protocol.py", line 779, in ensure_open await asyncio.shield(self.close_connection_task) File "Local_Addr\lib\asyncio\futures.py", line 260, in __await__ yield self # This tells Task to wait for completion

I also checked not to send any data if connection is closed ( by "ws.closed") and it didn't make any difference. I'm really in hurry and any help will be appreciated.