Skip to content

Commit 688825a

Browse files
author
Damien Tournoud
committed
Properly close the command when the connection close unexpectedly.
We need to properly handle three cases: - eofReceived(): we receive an EOF on the SSH channel, we need to close the stdin of the process and let it deal with that. - closed(): the connection is closed, we need to kill the process - the connection is closed while we were (asynchronously) authenticating: we need to not open the process. Most of the code is taken straight from `twisted.conch.unix`.
1 parent 12fe0b1 commit 688825a

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

drupalGitSSHDaemon.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,12 @@ def execGitCommand(self, auth_values, argv, proto):
288288
repopath, user, auth_service = auth_values
289289
sh = self.user.shell
290290
repo_id = auth_service["repo_id"]
291-
291+
292+
if proto.session.localClosed:
293+
# The channel has been closed while we were performing the
294+
# authentication request, exit.
295+
return
296+
292297
env = {}
293298
if user:
294299
# The UID is known, populate the environment
@@ -297,11 +302,19 @@ def execGitCommand(self, auth_values, argv, proto):
297302
env['VERSION_CONTROL_VCS_AUTH_DATA'] = json.dumps(auth_service)
298303

299304
command = ' '.join(argv[:-1] + ["'{0}'".format(repopath)])
300-
reactor.spawnProcess(proto, sh, (sh, '-c', command), env=env)
305+
self.pty = reactor.spawnProcess(proto, sh, (sh, '-c', command), env=env)
301306

302-
def eofReceived(self): pass
307+
def eofReceived(self):
308+
if self.pty:
309+
self.pty.closeStdin()
303310

304-
def closed(self): pass
311+
def closed(self):
312+
if self.pty:
313+
try:
314+
self.pty.signalProcess('HUP')
315+
except (OSError,ProcessExitedAlready):
316+
pass
317+
self.pty.loseConnection()
305318

306319

307320
class GitConchUser(ConchUser):

0 commit comments

Comments
 (0)