agoragames / haigha

AMQP Python client
BSD 3-Clause "New" or "Revised" License
160 stars 41 forks source link

Socket fds are leaked upon connection failure #95

Open orishoshan opened 7 years ago

orishoshan commented 7 years ago

python 1084 3041 root 268u sock 0,7 0t0 21240 can't identify protocol python 1084 3041 root 269u sock 0,7 0t0 21253 can't identify protocol python 1084 3041 root 270u sock 0,7 0t0 23762 can't identify protocol

... and so on. In my case, a service was attempting to reconnect to RabbitMQ periodically after the connection was severed, and kept failing for a long time. This eventually exhausted the fd limit, making the service unable to function.

This happens when SocketTransport.connect fails to connect (specificallt, when a socket.error is closed), and the loop continues to the next iteration. In that case, the socket is never closed, and the connection is left half-closed.

These connections do not show up in netstat (on Linux). You can detect them with lsof, where they appear as "can't identify protocol".

Fixed in PR #96.

vitaly-krugl commented 7 years ago

good catch