rdeepak2002 / reddit-place-script-2022

Script to draw an image onto r/place (https://www.reddit.com/r/place/)
909 stars 347 forks source link

[BUG] WebSocketConnectionClosedException: Connection to remote host was lost. #348

Open Adenser opened 2 years ago

Adenser commented 2 years ago

Bug Report Form

Checklist

Describe the bug

The script is losing connection with the server after 2-3 hours of nonstop running

    Exception in thread Thread-1:
    Traceback (most recent call last):
    File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
    File "/usr/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
    File "/root/place/XY14/main.py", line 684, in task
    current_r, current_c, new_rgb = self.get_unset_pixel(
    File "/root/place/XY14/main.py", line 477, in get_unset_pixel
    boardimg = self.get_board(self.access_tokens[index])
    File "/root/place/XY14/main.py", line 314, in get_board
    msg = ws.recv()
    File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 357, in recv
    opcode, data = self.recv_data()
    File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 380, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
    File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 401, in recv_data_frame
    frame = self.recv_frame()
    File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 440, in recv_frame
    return self.frame_buffer.recv_frame()
    File "/usr/local/lib/python3.9/dist-packages/websocket/_abnf.py", line 338, in recv_frame
    self.recv_header()
    File "/usr/local/lib/python3.9/dist-packages/websocket/_abnf.py", line 294, in recv_header
    header = self.recv_strict(2)
    File "/usr/local/lib/python3.9/dist-packages/websocket/_abnf.py", line 373, in recv_strict
    bytes_ = self.recv(min(16384, shortage))
    File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 524, in _recv
    return recv(self.sock, bufsize)
    File "/usr/local/lib/python3.9/dist-packages/websocket/_socket.py", line 122, in recv
    raise WebSocketConnectionClosedException(
    websocket._exceptions.WebSocketConnectionClosedException: Connection to remote host was lost.

To Reproduce

Steps to trigger the bug:

Run the script for a few hours on VPS

Expected behavior

Code not to lose connection?

Additional context

The script is running on Hetzner VPS in screen.

It maybe has something in common when the script has nothing to do. Thread 1 did action @ 00:09, and at 00:12 it crashed. I noticed this error appearing long before in different versions.

Adenser commented 2 years ago

Additional log with debug enabled. I wonder if high CPU usage might be the cause of this?

Account Placing:
2022-04-04 12:01:37.936 | INFO     | __main__:set_pixel_and_check_ratelimit:223 - Thread #1 : Attempting to place Dark Blue (12) pixel at CEN, SOR
2022-04-04 12:01:38.453 | DEBUG    | __main__:set_pixel_and_check_ratelimit:260 - Thread #1 : Received response: {"data":{"act":{"data":[{"id":"65njk56-fgf5-4d3f-86e8-54s4y54","data":{"nextAvailablePixelTimestamp":1.649066798e+12,"__typename":"GetUserCooldownResponseMessageData","__typename":"GetUserCooldownResponseMessageData"},"__typename":"BasicMessage","__typename":"BasicMessage"},{"id":"65njk56-fgf5-4d3f-86e8-54s4y54","data":{"timestamp":1.649066498127e+12,"__typename":"SetPixelResponseMessageData","__typename":"SetPixelResponseMessageData"},"__typename":"BasicMessage","__typename":"BasicMessage"}],"__typename":"ActResponse"}}}
2022-04-04 12:01:38.492 | INFO     | __main__:set_pixel_and_check_ratelimit:280 - Thread #1 : Succeeded placing pixel
2022-04-04 12:01:38.492 | DEBUG    | __main__:get_board:291 - Connecting and obtaining board images
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
File "/usr/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
File "/root/place/XXYY/main.py", line 684, in task
    current_r, current_c, new_rgb = self.get_unset_pixel(
File "/root/place/XXYY/main.py", line 477, in get_unset_pixel
    boardimg = self.get_board(self.access_tokens[index])
File "/root/place/XXYY/main.py", line 314, in get_board
    msg = ws.recv()
File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 357, in recv
    opcode, data = self.recv_data()
File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 380, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 401, in recv_data_frame
    Frame = self.recv_frame()
File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 440, in recv_frame
    return self.frame_buffer.recv_frame()
File "/usr/local/lib/python3.9/dist-packages/websocket/_abnf.py", line 338, in recv_frame
    self.recv_header()
File "/usr/local/lib/python3.9/dist-packages/websocket/_abnf.py", line 294, in recv_header
    header = self.recv_strict(2)
File "/usr/local/lib/python3.9/dist-packages/websocket/_abnf.py", line 373, in recv_strict
    bytes_ = self.recv(min(16384, shortage))
File "/usr/local/lib/python3.9/dist-packages/websocket/_core.py", line 524, in _recv
    return recv(self.sock, bufsize)
File "/usr/local/lib/python3.9/dist-packages/websocket/_socket.py", line 122, in recv
    raise WebSocketConnectionClosedException(
websocket._exceptions.WebSocketConnectionClosedException: Connection to remote host was lost.
2022-04-04 12:01:58.513 | DEBUG    | __main__:get_board:291 - Connecting and obtaining board images
Adenser commented 2 years ago

After updating the script to the #398 CPU Usage fix, the issue is still there. So probably wasn't usage after all