Skip to content

Commit

Permalink
Fix vcs package upgrade task termination
Browse files Browse the repository at this point in the history
This commit fixes an issue, which caused an upgrade task not being terminated
in case an invoked git/hg subprocess got stuck. An error message was displayed,
but corresponding `proc.communicate()` never exited.

To fix it, `proc.communicate(..., timeout=60)` is used to gracefully return
in case of stuck sub processes.
  • Loading branch information
deathaxe committed Sep 7, 2024
1 parent ef3bf19 commit c17c061
Showing 1 changed file with 28 additions and 37 deletions.
65 changes: 28 additions & 37 deletions package_control/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ def execute(self, args, cwd, input=None, encoding='utf-8', meaningful_output=Fal
if input and isinstance(input, str):
input = input.encode(encoding)

stuck = True

binary_name = os.path.basename(args[0])
if re.search('git', binary_name):
is_vcs = True
Expand All @@ -140,41 +138,7 @@ def execute(self, args, cwd, input=None, encoding='utf-8', meaningful_output=Fal
else:
is_vcs = False

if sublime:
def kill_proc():
if not stuck:
return
# This doesn't actually work!
proc.kill()

message = text.format(
'''
The process %s seems to have gotten stuck.
Command: %s
Working directory: %s
''',
(binary_name, create_cmd(args), orig_cwd)
)
if is_vcs:
message += text.format(
'''
This is likely due to a password or passphrase
prompt. Please ensure %s works without a prompt, or
change the "ignore_vcs_packages" Package Control
setting to true.
''',
binary_name
)
show_error(message)
sublime.set_timeout(kill_proc, 60000)

output, error = proc.communicate(input)

stuck = False

output, error = proc.communicate(input, timeout=60.0)
output = output.decode(encoding)
output = output.replace('\r\n', '\n').rstrip(' \n\r')

Expand Down Expand Up @@ -209,6 +173,33 @@ def kill_proc():

return output

except subprocess.TimeoutExpired:
proc.terminate()

message = text.format(
'''
The process %s seems to have gotten stuck.
Command: %s
Working directory: %s
''',
(binary_name, create_cmd(args), orig_cwd)
)
if is_vcs:
message += text.format(
'''
This is likely due to a password or passphrase
prompt. Please ensure %s works without a prompt, or
change the "ignore_vcs_packages" Package Control
setting to true.
''',
binary_name
)
show_error(message)
return False

except (OSError) as e:
show_error(
'''
Expand Down

0 comments on commit c17c061

Please sign in to comment.