question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Unexpected exception trying to send to websocket: code = 1006 (connection closed abnormally [internal])

See original GitHub issue

Describe the bug Unexpected exception trying to send to websocket: code = 1006 (connection closed abnormally [internal])

To Reproduce Steps to reproduce the behavior:

  1. npm run electron &
  2. Wait about 3~5 hours
  3. chia daemon exit
  4. See error

Expected behavior Working fine

Screenshots Screenshot from 2021-04-26 22-57-52

Desktop (please complete the following information):

  • OS: Linux
  • OS Version/Flavor: Ubuntu 20.04
  • CPU: 5950X

Additional context

debug.log

  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 827, in transfer_data
    message = await self.read_message()
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 895, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 971, in read_data_frame
    frame = await self.read_frame(max_size)
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 1047, in read_frame
    frame = await Frame.read(
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/framing.py", line 105, in read
    data = await reader(2)
  File "/usr/lib/python3.8/asyncio/streams.py", line 721, in readexactly
    raise exceptions.IncompleteReadError(incomplete, n)
asyncio.exceptions.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 "/home/chia-miner/chia-blockchain/chia/daemon/server.py", line 182, in safe_handle
    await socket.send(response)
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 555, in send
    await self.ensure_open()
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 803, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason

2021-04-26T22:49:52.481 daemon chia.daemon.server         : INFO     Websocket exception. Closing websocket with chia_harvester code = 1006 (connection closed abnormally [internal]), no reason Traceback (most recent call last):
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 827, in transfer_data
    message = await self.read_message()
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 895, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 971, in read_data_frame
    frame = await self.read_frame(max_size)
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 1047, in read_frame
    frame = await Frame.read(
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/framing.py", line 105, in read
    data = await reader(2)
  File "/usr/lib/python3.8/asyncio/streams.py", line 723, in readexactly
    await self._wait_for_data('readexactly')
  File "/usr/lib/python3.8/asyncio/streams.py", line 517, in _wait_for_data
    await self._waiter
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 846, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

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

Traceback (most recent call last):
  File "/home/chia-miner/chia-blockchain/chia/daemon/server.py", line 167, in safe_handle
    async for message in websocket:
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 439, in __aiter__
    yield await self.recv()
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 509, in recv
    await self.ensure_open()
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 803, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason

2021-04-26T22:49:52.481 daemon chia.daemon.server         : INFO     Websocket exception. Closing websocket with Unknown code = 1006 (connection closed abnormally [internal]), no reason Traceback (most recent call last):
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 827, in transfer_data
    message = await self.read_message()
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 895, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 971, in read_data_frame
    frame = await self.read_frame(max_size)
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 1047, in read_frame
    frame = await Frame.read(
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/framing.py", line 105, in read
    data = await reader(2)
  File "/usr/lib/python3.8/asyncio/streams.py", line 721, in readexactly
    raise exceptions.IncompleteReadError(incomplete, n)
asyncio.exceptions.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 "/home/chia-miner/chia-blockchain/chia/daemon/server.py", line 167, in safe_handle
    async for message in websocket:
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 439, in __aiter__
    yield await self.recv()
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 509, in recv
    await self.ensure_open()
  File "/home/chia-miner/chia-blockchain/venv/lib/python3.8/site-packages/websockets/protocol.py", line 803, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason

2021-04-26T22:49:52.482 daemon chia.daemon.server         : INFO     Daemon WebSocketServer closed

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:29 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
noisymimecommented, May 16, 2021

But will it affect farming in anyway?

I’ve been playing with this and as best as I can tell, the answer is Yes. When this starts occurring in the logs I see my response times grow dramatically, going from around 1000ms at most to averages of 17000ms and maximums well above 50000ms. I can’t confirm for certain that it’s impacting farming, but that seems worrying.

Just for reference, you don’t need to restart your whole machine to resolve this, you can do the following (Note the -d as you must restart the daemon itself):

chia stop -d all
chia start harvester

The issue here is in daemon/server.py and seems to be as a result of the high value used for ping_interval on the websocket (500). From everything I’ve read 500 seconds (Just over 8 minutes) is far too high and can result in these broken sockets, particularly with some NAT setups. I’ve adjusted the value to 20 and am not seeing the issue reoccurring yet.

20s seems to be a much more sensible value and will not impose any significant overhead on either the client or server.

@ArrayZoneYour I think this issue needs to be looked at more seriously. Could you please reopen this issue? (Or if not I’ll raise a new one with these findings as there still seems to be an issue).

1reaction
dorofinocommented, May 31, 2021

It appears to be a case of your operating system and python collectively not cleaning up after themselves, and leaving certain sockets in use after the programs terminate processes uncleanly. For the time being the only practical solution is to simply first try to restart your chia daemon and if that fails to address it then reboot your system.

Great, that makes sense. Does this affect farming?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected exception trying to send to websocket: code = 1006
Unexpected exception trying to send to websocket: code = 1006 ... code = 1006 (connection closed abnormally [internal]), no reason.
Read more >
What Is Meant By Channels Error 1006? - Pusher
When a WebSocket connection is closed without a "close frame", the pusher-js library emits an error with code 1006. Usually this is caused...
Read more >
Websocket closes unexpectedly with error 1006
I am having issues with futures websocket where I randomly get 1006 error. ... code = 1006 (connection closed abnormally [internal]), no reason)....
Read more >
CloseEvent.code - Web APIs - MDN Web Docs
The code read-only property of the CloseEvent interface returns a WebSocket connection close code indicating the reason the server gave for ...
Read more >
websockets.exceptions — websockets 8.1 documentation
[docs]class ConnectionClosed(WebSocketException): """ Raised when trying to interact with a closed connection. Provides the connection close code and reason ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found