Skip to content

Commit a56b03b

Browse files
authored
Better error handling to prevent flaky test_last_chance_exception_handling test (#44909)
If the launched subprocess (which in tests just _immediately_ raises an Exception) exits very quickly before we even try to send the startup message it would fail with a BrokenPipeError. All we need to do in this case is handle it as the exit code of the task and it's message (which we already test) will cover it. This particular behaviour is hard to reliably catch in tests, so no tests are added here.
1 parent 87b6373 commit a56b03b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

task_sdk/src/airflow/sdk/execution_time/supervisor.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,13 @@ def _on_child_started(self, ti: TaskInstance, path: str | os.PathLike[str], requ
412412

413413
# Send the message to tell the process what it needs to execute
414414
log.debug("Sending", msg=msg)
415-
self.stdin.write(msg.model_dump_json().encode())
416-
self.stdin.write(b"\n")
415+
416+
try:
417+
self.stdin.write(msg.model_dump_json().encode())
418+
self.stdin.write(b"\n")
419+
except BrokenPipeError:
420+
# Debug is fine, the process will have shown _something_ in it's last_chance exception handler
421+
log.debug("Couldn't send startup message to Subprocess - it died very early", pid=self.pid)
417422

418423
def kill(
419424
self,

0 commit comments

Comments
 (0)