# HG changeset patch # User Nikolai.Kulakov@UNIT-1322.Labs.IntelliJ.Net # Date 1548951264 -10800 # Node ID 17bd4181c476f5a071db7f62a9a912082327146e # Parent b05a042511da6c8a254c0e4663cb33243e28f2de TW-55105 Add "teamcity.hg.command.readBytesLimit" to avoid OutOfMemoryError on input reading diff -r b05a042511da -r 17bd4181c476 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettings.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettings.java Fri Oct 19 15:42:44 2018 +0200 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettings.java Thu Jan 31 19:14:24 2019 +0300 @@ -29,6 +29,7 @@ */ public class CommandSettings { + private final int myReadBytesLimit = TeamCityProperties.getInteger("teamcity.hg.command.readBytesLimit", Integer.MAX_VALUE); private int myTimeout = TeamCityProperties.getInteger("teamcity.hg.command.defaultExecutionTimeout", 3600); private final Set myPrivateData = new HashSet(); private boolean myCheckForFailure = true; @@ -41,6 +42,10 @@ private boolean myUseCommandlineViaFileWrapper = false; private MercurialProgress myProgress = MercurialProgress.NO_OP; + public int getReadBytesLimit() { + return myReadBytesLimit; + } + public final int getMaxCommandLineSize() { return myUseCommandlineViaFileWrapper ? Integer.MAX_VALUE : OS.getMaxCommandLineSize(); } diff -r b05a042511da -r 17bd4181c476 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java Fri Oct 19 15:42:44 2018 +0200 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java Thu Jan 31 19:14:24 2019 +0300 @@ -104,7 +104,7 @@ } private static CommandResult runCommandWithName(MercurialCommandLine cli, CommandSettings settings, String command) throws VcsException { - CommandResult res = run(cli, settings.getTimeout(), command, settings.getPrivateData(), settings); + CommandResult res = run(cli, settings.getTimeout(), settings.getReadBytesLimit(), command, settings.getPrivateData(), settings); if (settings.isCheckForFailure() || settings.isFailWithNonEmptyStderr()) res.checkFailure(settings.isFailWithNonEmptyStderr()); logCommandOutput(command, res, settings); @@ -114,6 +114,7 @@ @NotNull private static CommandResult run(@NotNull final MercurialCommandLine cli, final int executionTimeout, + final int readBytesLimit, @NotNull final String command, @NotNull final Set privateData, @NotNull CommandSettings settings) { @@ -127,18 +128,30 @@ } else { stderrBuffer = new ByteArrayOutputStream(); } - ExecResult res = SimpleCommandLineProcessRunner.runCommandSecure(cli.toGeneralCommandLine(), command, null, new SimpleCommandLineProcessRunner.ProcessRunCallbackAdapter() { - @Override - public Integer getOutputIdleSecondsTimeout() { - return executionTimeout; - } + ExecResult res = SimpleCommandLineProcessRunner.runCommandSecure( + cli.toGeneralCommandLine(), command, null, + new SimpleCommandLineProcessRunner.ProcessRunCallback() { + @Override + public void onProcessStarted(@NotNull Process ps) { + } - @Override - public void onProcessFinished(@NotNull Process ps) { - long duration = System.currentTimeMillis() - start; - Loggers.VCS.debug("Command " + command + " took " + duration + "ms"); - } - }, stdoutBuffer, stderrBuffer); + @Override + public void onProcessFinished(@NotNull Process ps) { + long duration = System.currentTimeMillis() - start; + Loggers.VCS.debug("Command " + command + " took " + duration + "ms"); + } + + @Override + public Integer getOutputIdleSecondsTimeout() { + return executionTimeout; + } + + @Override + public Integer getMaxAcceptedOutputSize() { + return readBytesLimit; + } + }, + stdoutBuffer, stderrBuffer); return new CommandResult(Loggers.VCS, command, res, privateData, settings, cli.getWorkingDirectory()); }