asyncio.start_server, number of connections and then lock-up #15762
-
I am running a simple asyncio server listening for several clients. One of the clients (socket and not asyncio-based) sends a brief message and then closes. If I hit the server with multiple messages, say 10-15 seconds apart, the server appears to lock-up after 6, 7, 8 or 9 attempts.
Sometimes after 5 minutes I can start sending messages again and sometimes after waiting about 20 minutes I get: Should I be configuring something to drop the connection after use? Thanks for any keywords I can read-up on. Is this where I need to look: Or better still? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Do you have code to close the connection when you're done? Something like below. async def on_connect(self, reader, writer):
# Read request and send reply.
# Then close connection.
await writer.drain()
writer.close()
await writer.wait_closed()
reader.close()
await reader.wait_closed() |
Beta Was this translation helpful? Give feedback.
My experience with asyncio thus far has been with an HTTP server, that closes the connection after each request is serviced, and an FTP server that keeps a control open until the user logs out. So, you can do either. But, you can only have so many open connections. I think the default is five, but I could be wrong.
If the client is making a connection, sending something, then closing the connection, you should be closing on the server side as well. Otherwise, you're going to end up with a bunch of connections tied up in a FINWAIT state. If you've got a tool like netstat on your client side, you can see it. Eventually, the client will time out and drop these. That's probably why it starts …