HelloZeroNet / ZeroNet

ZeroNet - Decentralized websites using Bitcoin crypto and BitTorrent network
https://zeronet.io
Other
18.27k stars 2.26k forks source link

Cannot watch more than 1024 sockets #1663

Closed blurHY closed 2 years ago

blurHY commented 5 years ago

rev 3611 win10

[2018-09-27 21:05:53,911] ERROR    - Unhandled exception
Traceback (most recent call last):
  File "site-packages\gevent\baseserver.py", line 197, in _do_read
  File "site-packages\gevent\server.py", line 158, in do_read
  File "site-packages\gevent\_socket2.py", line 198, in accept
  File "site-packages\gevent\_socket2.py", line 124, in __init__
  File "gevent.libev.corecext.pyx", line 487, in gevent.libev.corecext.loop.io (src/gevent/libev/gevent.corecext.c:6680)
  File "gevent.libev.corecext.pyx", line 835, in gevent.libev.corecext.io.__init__ (src/gevent/libev/gevent.corecext.c:11088)
IOError: cannot watch more than 1024 sockets
[2018-09-27 21:05:54,029] ERROR    - Unhandled exception
Traceback (most recent call last):
  File "site-packages\gevent\baseserver.py", line 197, in _do_read
  File "site-packages\gevent\server.py", line 158, in do_read
  File "site-packages\gevent\_socket2.py", line 198, in accept
  File "site-packages\gevent\_socket2.py", line 124, in __init__
  File "gevent.libev.corecext.pyx", line 487, in gevent.libev.corecext.loop.io (src/gevent/libev/gevent.corecext.c:6680)
  File "gevent.libev.corecext.pyx", line 835, in gevent.libev.corecext.io.__init__ (src/gevent/libev/gevent.corecext.c:11088)
IOError: cannot watch more than 1024 sockets
[2018-09-27 21:05:54,505] ERROR    TorManager Tor controller connect error: error: [Errno 10061] [Error 10061] Ŀܾ޷ӡ in TorManager.py line 190 > _socket2.py line 231
[2018-09-27 21:05:56,549] ERROR    TorManager Error starting Tor client: IOError: cannot watch more than 1024 sockets in TorManager.py line 107 > TorManager.py line 179 > TorManager.py line 185 > _socket2.py line 124 > gevent.libev.corecext.pyx line 487 > gevent.libev.corecext.pyx line 835
[2018-09-27 21:05:57,075] ERROR    - Unhandled exception
Traceback (most recent call last):
  File "site-packages\gevent\baseserver.py", line 197, in _do_read
  File "site-packages\gevent\server.py", line 158, in do_read
  File "site-packages\gevent\_socket2.py", line 198, in accept
  File "site-packages\gevent\_socket2.py", line 124, in __init__
  File "gevent.libev.corecext.pyx", line 487, in gevent.libev.corecext.loop.io (src/gevent/libev/gevent.corecext.c:6680)
  File "gevent.libev.corecext.pyx", line 835, in gevent.libev.corecext.io.__init__ (src/gevent/libev/gevent.corecext.c:11088)
IOError: cannot watch more than 1024 sockets

Restarting zeronet doesn't help me.

blurHY commented 5 years ago

@shortcutme

HelloZeroNet commented 5 years ago

How many connections do you see on the /Stats page?

krixano commented 5 years ago

Btw, the 1024 max sockets is a libev restriction on Windows.

blurHY commented 5 years ago

I've switched to ubuntu recently.So i don't know will this bug occurs again or not

krixano commented 5 years ago

Here on this page of Gevent docs:

Note: On Windows using the libev backend, gevent is limited to a maximum of 1024 open sockets due to limitations in libev. This limitation should not exist with the default libuv backend.

That leads me to believe it's Windows-only.

blurHY commented 5 years ago

So we should not run a zeronet spider on Windows.

purplesyringa commented 5 years ago

Bad idea.

HelloZeroNet commented 5 years ago

Probably it's fixed by moving to Python3 (tested on windows 10):

> py -3 test_limit.py
Max stdio: 512
Testing files...
Error: [Errno 24] Too many open files: 'test_limit.py'
Max: 8189
Testing sockets...
Error: [Errno 10055] [WinError 10055] An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.
Max: 16363

Python2 results:

> py -2 test_limit.py
Max stdio: 512
Testing files...
Error: [Errno 24] Too many open files: 'test_limit.py'
Max: 509
Testing sockets..
Error: cannot watch more than 1024 sockets
Max: 1021

So based on this testing Python2 process was limited to open 509 files and serve 1021 sockets at the same time, Python3 process can open 8189 files and serve 16363 sockets.

The script I used to test: https://gist.github.com/HelloZeroNet/d1f2d5424f4026def8558cc11ed2fa68

slrslr commented 4 years ago

Soon after following error ZeroNet crashed. No error crash message, no error.log.

ERROR - Unhandled exception: OSError: cannot watch more than 1024 sockets in lib/gevent/baseserver.py line 199 > ... > corecext.pyx line 640 > 1006

HelloZeroNet commented 4 years ago

I can confirm that it drops this error when using gevent.config.loop = "libev-cext"

It was changed from libuv to libev, because it had multiple issues with multi-threading + gevent libuv. https://github.com/HelloZeroNet/ZeroNet/commit/51f49cd45aa0677427683828a15d23316c91a9bd I will check if we can switch back to default libev with latest gevent.

slrslr commented 3 years ago

I see this error repeatedly when i try to start ZN. ZN run for a few minutes and then there is generic Windows 10 message with only option to terminate app.

[2020-10-13 00:39:47,388] INFO     - Libsecpk256k1 loaded: FFILibrary_U:\ZeroNet-win-dist-win64\lib\coincurve\libsecp256k1.dll in 0.246s
[2020-10-13 00:39:49,886] INFO     - Version: 0.7.2 r4538, Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)], Gevent: 1.4.0
...
[2020-10-13 00:49:43,359] INFO     Site:1abc.def [OK] someIPv4:0: Thanks, file data/users/siteaddresshere/content.json updated! 1/1
[2020-10-13 00:50:28,319] ERROR    - Unhandled exception: OSError: cannot watch more than 1024 sockets in lib/gevent/baseserver.py line 199 > ... > corecext.pyx line 640 > 1006
[2020-10-13 00:50:28,690] ERROR    - Unhandled exception: OSError: cannot watch more than 1024 sockets in lib/gevent/baseserver.py line 199 > ... > corecext.pyx line 640 > 1006

that errors are only ones in file and last ones at the end of file. see no error log file of ZN.

In previous startup attempt i also see error #2537 but maybe not related. ZN was starting OK, but when i clicked to update on updater zite, then ZN shown after some minutes the terminate windows prompt and now it show it always after start.