Skip to content

Commit a63f7a9

Browse files
committed
Attempt to fix race by removing request from book keeping before responding to Bazel
We were previously responding to Bazel about the request before removing the request from book keeping. That leaves a window for Bazel to send us another request with the same request ID before we've removed the original request from the worker's book keeping.
1 parent 6b13254 commit a63f7a9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/scala/higherkindness/rules_scala/common/worker/WorkerMain.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ abstract class WorkerMain[S](stdin: InputStream = System.in, stdout: PrintStream
6969
maybeExitCode: Option[Int],
7070
wasCancelled: Boolean = false,
7171
): Unit = {
72+
// Remove the request from our book keeping right before we respond to Bazel. If
73+
// we respond to Bazel about the request before removing it,then there is a race:
74+
// Bazel could make a request with the same requestId to this worker before the
75+
// requestId is removed from the worker's book keeping.
76+
//
77+
// Ideally Bazel will not send a request to this worker with the same requestId
78+
// as another request before we've responded to the original request. If that
79+
// happens, then there's a race regardless of what we do.
80+
activeRequests.remove(requestId)
81+
7282
// Defined here so all writes to stdout are synchronized
7383
stdout.synchronized {
7484
val builder = WorkerProtocol.WorkResponse.newBuilder
@@ -88,8 +98,6 @@ abstract class WorkerMain[S](stdin: InputStream = System.in, stdout: PrintStream
8898
.build()
8999
.writeDelimitedTo(stdout)
90100
}
91-
92-
activeRequests.remove(requestId)
93101
}
94102

95103
/**

0 commit comments

Comments
 (0)