Xiao-zhen-Liu commented on code in PR #4683:
URL: https://github.com/apache/texera/pull/4683#discussion_r3183672113
##########
amber/src/main/scala/org/apache/texera/amber/engine/architecture/worker/managers/OutputPortResultWriterThread.scala:
##########
@@ -35,15 +36,27 @@ class OutputPortResultWriterThread(
val queue: LinkedBlockingQueue[Either[Tuple, TerminateSignal]] =
Queues.newLinkedBlockingQueue[Either[Tuple, TerminateSignal]]()
+ // Captured failure from put-one or close() so the worker DP thread can
+ // re-throw and let the controller's pekko supervisor surface a FatalError
+ // to the client. Without this, the writer thread dies silently and the
+ // worker keeps reporting normal port completion to the controller while
+ // results are missing or stale, leading to e2e timeouts that hide the
+ // real cause.
+ @volatile private var failure: Option[Throwable] = None
+ def getFailure: Option[Throwable] = failure
+
override def run(): Unit = {
- var internalStop = false
- while (!internalStop) {
- val queueContent = queue.take()
- queueContent match {
- case Left(tuple) => bufferedItemWriter.putOne(tuple)
- case Right(_) => internalStop = true
+ try {
+ var internalStop = false
+ while (!internalStop) {
+ queue.take() match {
+ case Left(tuple) => bufferedItemWriter.putOne(tuple)
+ case Right(_) => internalStop = true
+ }
}
+ bufferedItemWriter.close()
+ } catch {
+ case NonFatal(e) => failure = Some(e)
Review Comment:
Both the loop and `close()` are now inside the same `try`, so a `putOne`
failure (e.g., a flush triggered mid-loop hitting the same iceberg condition)
bypasses `close()` entirely and leaks the underlying writer's file handles. It
is a pre-existing behavior, but you're already touching this code and the fix
is small:
```scala
override def run(): Unit = {
try {
var internalStop = false
while (!internalStop) {
queue.take() match {
case Left(tuple) => bufferedItemWriter.putOne(tuple)
case Right(_) => internalStop = true
}
}
} catch {
case NonFatal(e) => failure = Some(e)
} finally {
try bufferedItemWriter.close()
catch {
case NonFatal(e) =>
failure match {
case Some(orig) => orig.addSuppressed(e)
case None => failure = Some(e)
}
}
}
}
```
This also preserves both errors when `putOne` and `close()` fail in the same
run.
##########
amber/src/test/scala/org/apache/texera/amber/engine/architecture/worker/managers/OutputPortResultWriterThreadSpec.scala:
##########
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.amber.engine.architecture.worker.managers
+
+import org.apache.texera.amber.core.storage.model.BufferedItemWriter
+import org.apache.texera.amber.core.tuple.Tuple
+import org.apache.texera.amber.core.virtualidentity.ActorVirtualIdentity
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.engine.architecture.messaginglayer.{
+ NetworkOutputGateway,
+ OutputManager
+}
+import org.apache.texera.amber.engine.common.ambermessage.WorkflowFIFOMessage
+import org.scalatest.flatspec.AnyFlatSpec
+
+import scala.collection.mutable
+
+class OutputPortResultWriterThreadSpec extends AnyFlatSpec {
+
+ private class StubWriter(throwOnClose: Boolean = false) extends
BufferedItemWriter[Tuple] {
+ val bufferSize: Int = 1024
+ var closeCalled = false
+ def open(): Unit = ()
+ def putOne(item: Tuple): Unit = ()
+ def removeOne(item: Tuple): Unit = ()
+ def close(): Unit = {
+ closeCalled = true
+ if (throwOnClose) throw new RuntimeException("test close failure")
+ }
+ }
+
+ "OutputPortResultWriterThread" should "leave getFailure empty on a clean
run" in {
+ val writer = new StubWriter()
+ val thread = new OutputPortResultWriterThread(writer)
+ thread.start()
+ thread.queue.put(Right(PortStorageWriterTerminateSignal))
+ thread.join()
+ assert(thread.getFailure.isEmpty)
+ assert(writer.closeCalled)
+ }
+
+ it should "capture a close() exception in getFailure so the worker can
re-throw" in {
Review Comment:
Your doc on the `failure` variable says "put-one or close()" but only the
`close()` path is exercised. A `throwOnPutOne` variant of `StubWriter` would
cover it — and would catch the leak above before it regresses again.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]