Send messages in AsyncReceiveCommits from the main thread

Fixes a race condition between sending the "done" progress message and
the rest of ReceiveCommits' output, and avoids potentially blocking in
the worker thread.

Change-Id: I782ae467b594971287b73e246552eb64e07c1be5
This commit is contained in:
Dave Borowitz
2012-03-13 14:45:51 -07:00
parent 5447cd7cd7
commit 97f38ace82
2 changed files with 80 additions and 81 deletions

View File

@@ -34,6 +34,7 @@ import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.PreReceiveHook;
import org.eclipse.jgit.transport.ReceiveCommand;
import org.eclipse.jgit.transport.ReceiveCommand.Result;
import org.eclipse.jgit.transport.ReceivePack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -167,14 +168,16 @@ public class AsyncReceiveCommits implements PreReceiveHook {
timeoutMillis, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
log.warn("Error in ReceiveCommits", e);
rc.getMessageSender().sendError("internal error while processing changes");
rc.addError("internal error while processing changes");
// ReceiveCommits has tried its best to catch errors, so anything at this
// point is very bad.
for (final ReceiveCommand c : commands) {
if (c.getResult() == ReceiveCommand.Result.NOT_ATTEMPTED) {
rc.reject(c, "internal error");
if (c.getResult() == Result.NOT_ATTEMPTED) {
c.setResult(Result.REJECTED_OTHER_REASON, "internal error");
}
}
} finally {
rc.sendMessages();
}
}