@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Wait for the Git client to disconnect before exiting in Git SSH workflows

Summary:
Ref T2230. Very rarely, even though we've flushed the connection and sent all the data, we'll close the connection before Git is happy with it and it will flip out with an error like this:

fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

This is hard to reproduce because it depends on the order of read/write operations we can't directly control. I only saw it about 2% of the time, by just running `git pull` over and over again.

Waiting for Git to close its side of the connection seems to fix it.

Test Plan: Ran `git clone` a ton of times without seeing the error again. Ran `git push` a ton of times with new commits.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2230

Differential Revision: https://secure.phabricator.com/D7558

+21 -1
+1
src/applications/diffusion/ssh/DiffusionSSHGitReceivePackWorkflow.php
··· 35 35 $repository->writeStatusMessage( 36 36 PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE, 37 37 PhabricatorRepositoryStatusMessage::CODE_OKAY); 38 + $this->waitForGitClient(); 38 39 } 39 40 40 41 return $err;
+7 -1
src/applications/diffusion/ssh/DiffusionSSHGitUploadPackWorkflow.php
··· 21 21 22 22 $future = new ExecFuture('git-upload-pack %s', $repository->getLocalPath()); 23 23 24 - return $this->newPassthruCommand() 24 + $err = $this->newPassthruCommand() 25 25 ->setIOChannel($this->getIOChannel()) 26 26 ->setCommandChannelFromExecFuture($future) 27 27 ->execute(); 28 + 29 + if (!$err) { 30 + $this->waitForGitClient(); 31 + } 32 + 33 + return $err; 28 34 } 29 35 30 36 }
+13
src/applications/diffusion/ssh/DiffusionSSHGitWorkflow.php
··· 7 7 return parent::writeError($message."\n"); 8 8 } 9 9 10 + protected function waitForGitClient() { 11 + $io_channel = $this->getIOChannel(); 12 + 13 + // If we don't wait for the client to close the connection, `git` will 14 + // consider it an early abort and fail. Sit around until Git is comfortable 15 + // that it really received all the data. 16 + while ($io_channel->isOpenForReading()) { 17 + $io_channel->update(); 18 + $this->getErrorChannel()->flush(); 19 + PhutilChannel::waitForAny(array($io_channel)); 20 + } 21 + } 22 + 10 23 }