FrankYang0529 commented on code in PR #69254:
URL: https://github.com/apache/airflow/pull/69254#discussion_r3518295643
##########
java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Comm.kt:
##########
@@ -96,38 +82,34 @@ class CoordinatorComm(
) {
val data = encode(OutgoingFrame(id, body))
logger.debug("Sending", mapOf("id" to id, "body" to body))
- writer.writeByteArray(Frame.lengthPrefix(data.size))
- writer.writeByteArray(data)
- }
-
- suspend fun handleIncoming(frame: IncomingFrame) {
- when (val request = frame.body) {
- null -> {}
- is ErrorResponse -> throw ApiError("[${request.error}]
${request.detail}")
- is StartupDetails -> {
- communicate<Unit>(runTask(bundle, request, this))
- shutDownRequested = true
- }
+ writeMutex.withLock {
+ writer.writeByteArray(Frame.lengthPrefix(data.size))
+ writer.writeByteArray(data)
}
}
@Throws(ApiError::class)
suspend fun communicateImpl(body: Any): Any {
val requestId = nextId.fetchAndAdd(1)
- return commMutex.withLock {
- var frame: IncomingFrame? = null
+ val waiter = CompletableDeferred<IncomingFrame>()
- suspend fun handle(f: IncomingFrame) {
- frame = f
+ stateMutex.withLock {
+ readError?.let { throw it }
+ if (!dispatcherStarted) {
+ dispatcherStarted = true
+ dispatcherScope.launch { readLoop() }
}
+ pending[requestId] = waiter
+ }
+
+ try {
sendMessage(requestId, body)
- processOnce(::handle)
- val received = frame ?: throw ApiError("No response received")
- if (received.id != requestId) {
- throw ApiError("response id ${received.id} does not match request id
$requestId")
- }
- received.body ?: Unit
+ } catch (e: Throwable) {
+ stateMutex.withLock { pending.remove(requestId) }
+ throw e
}
+
+ return waiter.await().body ?: Unit
Review Comment:
Thanks for catching this. I will handle in the next PR.
--
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]