diff options
author | John Estabrook <jestabro@vyos.io> | 2021-02-17 15:25:54 -0600 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2021-02-18 14:30:37 -0600 |
commit | c0bc1782f3c92033aa1224e220c8147cd031a23e (patch) | |
tree | 9b310f3b14673669d4bea51340011769bc53ca5e | |
parent | 8d41bc6f721979780e03a0d0d22c53c0e41b54ad (diff) | |
download | vyos-1x-c0bc1782f3c92033aa1224e220c8147cd031a23e.tar.gz vyos-1x-c0bc1782f3c92033aa1224e220c8147cd031a23e.zip |
configsession: T3259: avoid deadlock when data fills stdout pipe
If the subprocess is producing enough data (in this case showConfig on a
large config file), then the construction:
p = subprocess.Popen(.., stdout=subprocess.PIPE, ..)
p.wait()
will deadlock with the subprocess waiting for data to be consumed, while
the Python process waits for its termination. So consume data, then wait
for termination.
(cherry picked from commit 83bcd13775323bec35d018223029e9a8b13179c8)
-rw-r--r-- | python/vyos/configsession.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/python/vyos/configsession.py b/python/vyos/configsession.py index 82b9355a3..670e6c7fc 100644 --- a/python/vyos/configsession.py +++ b/python/vyos/configsession.py @@ -129,9 +129,9 @@ class ConfigSession(object): def __run_command(self, cmd_list): p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=self.__session_env) + (stdout_data, stderr_data) = p.communicate() + output = stdout_data.decode() result = p.wait() - output = p.stdout.read().decode() - p.communicate() if result != 0: raise ConfigSessionError(output) return output |