pyftpdlib icon indicating copy to clipboard operation
pyftpdlib copied to clipboard

Enable TCP keepalive

Open wcs1only opened this issue 10 years ago • 4 comments

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.

wcs1only avatar Apr 04 '16 18:04 wcs1only

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" [email protected] 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

giampaolo avatar Apr 04 '16 18:04 giampaolo

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 avatar Apr 04 '16 18:04 wcs1only

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

wcs1only avatar Apr 04 '16 19:04 wcs1only

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

giampaolo avatar Apr 26 '18 10:04 giampaolo