giampaolo / pyftpdlib

Extremely fast and scalable Python FTP server library
MIT License
1.68k stars 264 forks source link

fix a bug that may cause zombie processes #448

Closed yuyang733 closed 3 years ago

yuyang733 commented 6 years ago

Recently, I used pyftpdlib to develop a ftp server program, which helps me to greatly reduce the development cycle. However, at the same time, I also found a bug that it would cause the zombie process after login and exit every time. Here, I use the MultiprocessFTPServer to instantiate a server object. My source code is as follows:

...
    if masquerade_address is not None:
        handler.masquerade_address = masquerade_address

    handler.passive_ports = passive_ports

    server = MultiprocessFTPServer(("0.0.0.0", port), handler)

    try:
        server.serve_forever()
    finally:
        server.close_all()
...

I found that the pyftpdlib always create a new process to handle a new connection each time and it does not wait for these processes whenever the connection is broken. Only when the server process exits, does it wait for all the sub processes in a unified way. The following is some screenshots on the bug: login operation use 'ps' command

I think using a thread to periodically wait for all the tasks might be a good solution. Submitted code has been carefully tested and can prove to be effective.

In addition, I also found that the maximum number of connections seems to not work for MultiprocessFTPServer.

liuchang0812 commented 6 years ago

@giampaolo ping

FelixSchwarz commented 6 years ago

Not sure but it looks like this pull problem was also fixed by 37236bfdaf51cd9d0c5759560a391771765a2ee8 ?