-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to connect creates file descriptors and doesn't free them #1113
Comments
Looks like replacing Solves the problem, because |
I'd rather catch |
Ok, thanks |
Let's do this! |
This solves issue with sockets leaking python-websockets/websockets#1113 if websocket server timeouts
This solves issue with sockets leaking python-websockets/websockets#1113 if websocket server timeouts
This solves issue with sockets leaking python-websockets/websockets#1113 if websocket server timeouts
Full script to reproduce: import asyncio
import time
import websockets.client
import os
import threading
async def _run_server():
server = await asyncio.start_server(
lambda r, w: None, '127.0.0.1', 8888)
addrs = ', '.join(str(sock.getsockname()) for sock in server.sockets)
print(f'Serving on {addrs}')
async with server:
await server.serve_forever()
def run_server():
asyncio.run(_run_server())
async def run():
while True:
try:
async with websockets.client.connect('ws://127.0.0.1:8888', ping_interval=1, ping_timeout=.5, open_timeout=1, close_timeout=1) as self.websocket:
pass
except asyncio.TimeoutError:
f = list(os.scandir('/proc/%d/fd' % os.getpid()))
print('timeout, fd size=%d' % len(f))
if __name__ == "__main__":
srv_thread = threading.Thread(target=run_server)
srv_thread.start()
time.sleep(1)
asyncio.run(run())
Is common pattern to wrap some functions in |
Since python3.8 CancelledError is subclass of BaseException Test server is spawned in separate process to avoid counting server sockets Closes: python-websockets#1113
I agree that catching I wrote a test that is closer in style to other tests (regardless of the fact that this test suite is a tire fire). |
I have a use case where I want to try to connect to some WebSocket that is not always available. I am continuously wrapping my code in a loop that creates the socket and uses it.
However, if the connection keeps on failing with
asyncio.TimeoutError
, it looks like the number of file descriptios is blowing up, as you can see with below example:Outputs:
Until it finally reaches "Too many open files".
Is it a bad pattern fo this use case, or is this a bug ?
The text was updated successfully, but these errors were encountered: