Skip to content

Commit

Permalink
Better error handling to prevent flaky test_last_chance_exception_han…
Browse files Browse the repository at this point in the history
…dling test (apache#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.
  • Loading branch information
ashb authored Dec 13, 2024
1 parent 87b6373 commit a56b03b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions task_sdk/src/airflow/sdk/execution_time/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,13 @@ def _on_child_started(self, ti: TaskInstance, path: str | os.PathLike[str], requ

# Send the message to tell the process what it needs to execute
log.debug("Sending", msg=msg)
self.stdin.write(msg.model_dump_json().encode())
self.stdin.write(b"\n")

try:
self.stdin.write(msg.model_dump_json().encode())
self.stdin.write(b"\n")
except BrokenPipeError:
# Debug is fine, the process will have shown _something_ in it's last_chance exception handler
log.debug("Couldn't send startup message to Subprocess - it died very early", pid=self.pid)

def kill(
self,
Expand Down

0 comments on commit a56b03b

Please sign in to comment.