FrankYang0529 commented on code in PR #69254:
URL: https://github.com/apache/airflow/pull/69254#discussion_r3518293694
##########
java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Comm.kt:
##########
@@ -138,4 +120,56 @@ class CoordinatorComm(
else -> throw ApiError("Unexpected response type
${response::class.java}")
}
}
+
+ override fun close() {
+ dispatcherScope.cancel()
+ }
+
+ private suspend fun readFrame(): IncomingFrame {
+ val prefix = reader.readByteArray(4) // First 4 bytes as length.
+ if (prefix.size != 4) {
+ throw ApiError("Coordinator socket closed while reading frame length")
+ }
+ val payloadLength = Frame.parseLengthPrefix(prefix)
+ val payload = reader.readByteArray(payloadLength)
+ if (payload.size != payloadLength) {
+ throw ApiError("Coordinator socket closed while reading frame payload")
+ }
+ val frame = decode(payload)
+ logger.debug("Received", mapOf("id" to frame.id))
+ return frame
+ }
+
+ private suspend fun readLoop() {
+ while (true) {
+ val frame =
+ try {
+ readFrame()
+ } catch (e: CancellationException) {
+ // close() cancels the dispatcher.
+ throw e
+ } catch (e: Throwable) {
+ failAllWaiters(e)
+ return
+ }
+ val waiter = stateMutex.withLock { pending.remove(frame.id) }
+ if (waiter == null) {
+ logger.debug("Discarding frame with no matching waiter", mapOf("id" to
frame.id))
+ continue
+ }
Review Comment:
Changed to `warning`.
--
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]