From 2d47eaa13fbb23c38247dad27df8ea8625430ce6 Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Mon, 8 Feb 2016 14:02:24 +0000 Subject: Make The Build Faster: More explicit exception handling in the worker strategy. -- MOS_MIGRATED_REVID=114102899 --- .../devtools/build/lib/worker/WorkerPool.java | 23 ++++++++++++++++++++++ .../build/lib/worker/WorkerSpawnStrategy.java | 6 +++--- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerPool.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerPool.java index 03eb7d6a54..bf5e458a23 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerPool.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerPool.java @@ -13,12 +13,15 @@ // limitations under the License. package com.google.devtools.build.lib.worker; +import com.google.common.base.Throwables; import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.vfs.Path; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; +import java.io.IOException; + import javax.annotation.concurrent.ThreadSafe; /** @@ -47,4 +50,24 @@ final class WorkerPool extends GenericKeyedObjectPool { public void setVerbose(boolean verbose) { this.workerFactory.setVerbose(verbose); } + + @Override + public Worker borrowObject(WorkerKey key) throws IOException, InterruptedException { + try { + return super.borrowObject(key); + } catch (Throwable t) { + Throwables.propagateIfPossible(t, IOException.class, InterruptedException.class); + throw new RuntimeException("unexpected", t); + } + } + + @Override + public void invalidateObject(WorkerKey key, Worker obj) throws IOException, InterruptedException { + try { + super.invalidateObject(key, obj); + } catch (Throwable t) { + Throwables.propagateIfPossible(t, IOException.class, InterruptedException.class); + throw new RuntimeException("unexpected", t); + } + } } diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java index c079a8d941..20e0755be0 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java @@ -186,7 +186,7 @@ final class WorkerSpawnStrategy implements SpawnActionContext { String.format( "Worker process sent response with exit code: %d.", response.getExitCode())); } - } catch (Exception e) { + } catch (IOException e) { String message = CommandFailureUtils.describeCommandFailure( verboseFailures, spawn.getArguments(), env, execRoot.getPathString()); @@ -228,7 +228,7 @@ final class WorkerSpawnStrategy implements SpawnActionContext { private WorkResponse execInWorker( EventHandler eventHandler, WorkerKey key, WorkRequest request, int retriesLeft) - throws Exception { + throws IOException, InterruptedException, UserExecException { Worker worker = null; WorkResponse response = null; @@ -244,7 +244,7 @@ final class WorkerSpawnStrategy implements SpawnActionContext { "Worker process did not return a correct WorkResponse. This is probably caused by a " + "bug in the worker, writing unexpected other data to stdout."); } - } catch (Exception e) { + } catch (IOException | InterruptedException e) { if (e instanceof InterruptedException) { // The user pressed Ctrl-C. Get out here quick. retriesLeft = 0; -- cgit v1.2.3