giampaolo / pyftpdlib

Extremely fast and scalable Python FTP server library
MIT License
1.65k stars 267 forks source link

Enable TCP keepalive #377

Open wcs1only opened 8 years ago

wcs1only commented 8 years ago

There are some cloud based ftp clients & firewalls that get pretty sloppy about sending FIN packets when killing a long running control connection. When using MultiprocessFTPServer, this means we have a lot of unused processes lying around. I was able to solve this by setting socket.SO_KEEPALIVE in our handler, but I was wondering if you'd accept a patch to the base FTPServer class to enable this by default? Might save somebody a headache or too.

giampaolo commented 8 years ago

Mmm I am not exactly sure what you mean. By default the client gets automatically disconnected by the server after 5 minutes of inactivity. Isn't that enough already? What should SO_KEEPALIVE would accomplish? What issue are you experiencing exactly? Il 05/apr/2016 01:03, "Charlie Stanley" notifications@github.com ha scritto:

There are some cloud based ftp clients & firewalls that get pretty sloppy about sending FIN packets when killing a long running. When using MultiprocessFTPServer, this means we have a lot of unused processes lying around. I was able to solve this by setting socket.SO_KEEPALIVE in our handler, but I was wondering if you'd accept a patch to the base FTPServer class to enable this by default? Might save somebody a headache or too.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/giampaolo/pyftpdlib/issues/377

wcs1only commented 8 years ago

That was not the behavior I was observing. When using MultiprocessFTPServer, FTP connections that were not closed by the client (dropped by the AWS firewall) stayed in 'ESTABLISHED' state indefinitely, and the corresponding forked process never went away. They'd pile up until we hit max_cons and then no new connections could be served. When I enabled SO_KEEPALIVE, the connections would be closed by the OS and then cleaned up properly.

Perhaps the issue is that I'm using the OS provided version (v1.3.1) which is somewhat older. Is this something that would not appear in later versions?

wcs1only commented 8 years ago

These were control connections, not data connections, if that makes any difference.

giampaolo commented 6 years ago

This should be due to #447 hence SO_KEEPALIVE should not be necessary.