Mondego / SourcererCC

Sourcerer's Code Clone project
GNU General Public License v3.0
206 stars 69 forks source link

Fix deadlock in run_command in controller.py #19

Closed danhper closed 6 years ago

danhper commented 6 years ago

With the previous implementation, run_command could deadlock.

While stderr stays empty, p.stderr.readline() will block. In the meanwhile, stdout output will accumulate in the pipe buffer. Once this buffer becomes full (the size is io.DEFAULT_BUFFER_SIZE, 8192 on my machine), the program run by subprocess.Popen will block when trying to output to stdout, resulting in a deadlock.

As all this logic was doing was buffering the process output in Python and writing it to a file, we can directly pass the file descriptor to subprocess.Popen and let Popen.communicate handle this directly.

saini commented 6 years ago

Thank you for pointing this out and the pull request! Looking forward to more suggestions and contributions!