Linux RHEL运行Locust遇OSError: [Errno 97]问题求助
Locust启动报错:OSError: [Errno 97] Address family not supported by protocol
问题背景
已通过pip3 install locust完成Locust 2.13.0的安装,编写测试脚本后运行时触发Greenlet相关的地址族不支持错误,尝试过以下启动命令:
locust -f first_locust_file.pylocust -f first_locust_file.py --master
错误堆栈信息
[2022-11-06 12:02:03,635] acabista.remote.csb/INFO/locust.main: Starting Locust 2.13.0 Traceback (most recent call last): File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run File "/home/acabista/Documents/python_studies/env/lib/python3.8/site-packages/locust/web.py", line 473, in start_server self.server.serve_forever() File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/baseserver.py", line 398, in serve_forever self.start() File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/baseserver.py", line 336, in start self.init_socket() File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/pywsgi.py", line 1545, in init_socket StreamServer.init_socket(self) File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/server.py", line 180, in init_socket self.socket = self.get_listener(self.address, self.backlog, self.family) File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/server.py", line 192, in get_listener return _tcp_listener(address, backlog=backlog, reuse_addr=cls.reuse_addr, family=family) File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/server.py", line 284, in _tcp_listener sock = GeventSocket(family=family) File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/_socket3.py", line 133, in __init__ self._sock = self._gevent_sock_class(family, type, proto, fileno) OSError: [Errno 97] Address family not supported by protocol 2022-11-06T15:02:03Z <Greenlet at 0x7f014637a180: <bound method WebUI.start_server of <locust.web.WebUI object at 0x7f01463c0f70>>> failed with OSError [2022-11-06 12:02:03,639] acabista.remote.csb/CRITICAL/locust.web: Unhandled exception in greenlet: <Greenlet at 0x7f014637a180: <bound method WebUI.start_server of <locust.web.WebUI object at 0x7f01463c0f70>>> Traceback (most recent call last): File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run File "/home/acabista/Documents/python_studies/env/lib/python3.8/site-packages/locust/web.py", line 473, in start_server self.server.serve_forever() File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/baseserver.py", line 398, in serve_forever self.start() File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/baseserver.py", line 336, in start self.init_socket() File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/pywsgi.py", line 1545, in init_socket StreamServer.init_socket(self) File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/server.py", line 180, in init_socket self.socket = self.get_listener(self.address, self.backlog, self.family) File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/server.py", line 192, in get_listener return _tcp_listener(address, backlog=backlog, reuse_addr=cls.reuse_addr, family=family) File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/server.py", line 284, in _tcp_listener sock = GeventSocket(family=family) File "/home/acabista/Documents/python_studies/env/lib64/python3.8/site-packages/gevent/_socket3.py", line 133, in __init__ self._sock = self._gevent_sock_class(family, type, proto, fileno) OSError: [Errno 97] Address family not supported by protocol
当前环境依赖包列表
(env) [acabista@acabista ecomproj]$ pip list Package Version ------------------ ----------- Brotli 1.0.9 certifi 2022.9.24 charset-normalizer 2.1.1 click 8.1.3 ConfigArgParse 1.5.3 Flask 2.2.2 Flask-BasicAuth 0.2.0 Flask-Cors 3.0.10 gevent 22.10.2 geventhttpclient 2.0.8 greenlet 2.0.0.post0 idna 3.4 importlib-metadata 5.0.0 itsdangerous 2.1.2 Jinja2 3.1.2 locust 2.13.0 MarkupSafe 2.1.1 msgpack 1.0.4 pip 22.3 psutil 5.9.3 pyzmq 24.0.1 requests 2.28.1 roundrobin 0.0.4 setuptools 65.5.0 six 1.16.0 typing_extensions 4.4.0 urllib3 1.26.12 Werkzeug 2.2.2 wheel 0.37.1 zipp 3.10.0 zope.event 4.5.0 zope.interface 5.5.1
解决方法
1. 显式绑定IPv4地址
错误源于Locust默认尝试同时监听IPv4和IPv6,若环境不支持IPv6或配置受限,启动时指定绑定到IPv4的0.0.0.0或具体内网IP:
locust -f first_locust_file.py --host=http://你的目标服务地址 -H 0.0.0.0:8089
主节点启动命令:
locust -f first_locust_file.py --master --host=http://你的目标服务地址 -H 0.0.0.0:8089
2. 降级gevent版本
当前使用的gevent 22.10.2存在兼容性问题,降级至稳定版本:
pip install gevent==21.12.0
重新启动Locust即可。
3. 检查系统IPv6配置
若需使用IPv6,确认系统支持:
- 执行
cat /proc/sys/net/ipv6/conf/all/disable_ipv6,输出为1表示IPv6已禁用,可修改为0后重启网络服务。 - 检查防火墙是否开放IPv6的8089端口。
内容的提问来源于stack exchange,提问作者Andressa Cabistani
相关产品推荐
相关产品推荐

