You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AirflowTaskTimeout should inherit BaseException instead of Exception? #35644
errors= []
foriteminitems_to_process:
try:
process(item) # This can take several minutes/hours eachexceptExceptionase:
errors.append(e)
iferrors:
raiseException(......)
If the Airflow task time out, what happens is that it injects an AirflowTaskTimeout exception where the code is currently running now.
If the code is designed to capture exceptions, it will capture the timeout and potentially continue running for several hours anyway.
What you think should happen instead
I think it would be better if AirflowTaskTimeout was treated similarly to KeyboardInterrupt, so it need explicit except block to capture.
Moving it outside of the Exception inheritance tree to inherit directly from BaseException would solve that.
See https://docs.python.org/3/library/exceptions.html#exception-hierarchy
Timeouts are generally in place to be last resort of aborting process by the higher level system if the lower level code has bugs in it, so it's safer to assume that code that doesn't deal with catching timeout should be aborted.
Yes. good idea. Might be worth implementing it.
BTW. There is another problem with tasks running low-level C-code that are not interrupted by signal (and should be handled in yet another way) - see #35474 - but indeed when code is catching all exceptions, chaning timeout to BaseException should work well. Would you like to implement it @hterik ?
Yeah. But it's not the same issue (or at least I believe it's not) - I believe the original issue was connected with SIGALRM not being properly handled by long-running low-level c-code. Catching and ignoring exceptions is a bad programming habit by anyone who run task in a loop from example described hy @hterik. You should generally ignore known exceptions not all of them if you want to add them to the loop in the fashon described here.
We should still make the change to AirflowTaskTimeout inheriting from BaseException to handle this "bad programming" case of course - (we do not want our users to shoot themselves in a foot by not knowing that they are doing something wrong) - but I think Kafka case from #35474 was somethign entirely different (only loosely related). I highly doubt somone in Kafka code handles all exceptions this way - my guess is that SIGALRM was not handled there :)
Yeah. But it's not the same issue (or at least I believe it's not) - I believe the original issue was connected with SIGALRM not being properly handled by long-running low-level c-code.
To be honest we don't know what the reason in particular this cases. It could be both:
Redefine SIGALRM handlers in upstream code
To broad catch exceptions in libraries or user code
In second case when Airflow task SIGALARM works, we do not control in which place in Main thread code returns
In this case it will break Airflow timeout, and in addition it might breaks something else
try
... # <- returns hereexceptException:
pass
In case if handler return in this code block, then change inheritance wouldn't help at all
try
... # <- returns hereexcept: # or except BaseException:pass
The bug report and discussion seems to be a bit stale. Just looking through the PR it looks good and reasonable for me. There might be side effects but we can handle this via a newsfragment I think.
To be on the "safer" side we might put this to a "functional" release, meaning 2.9.0 so that people just upgrading for fixes do catch less "surprises".
Activity
potiuk commentedon Nov 15, 2023
Yes. good idea. Might be worth implementing it.
BTW. There is another problem with tasks running low-level C-code that are not interrupted by signal (and should be handled in yet another way) - see #35474 - but indeed when code is catching all exceptions, chaning timeout to BaseException should work well. Would you like to implement it @hterik ?
Taragolis commentedon Nov 15, 2023
That is exactly what a Option 1 propose 😄
hterik commentedon Nov 15, 2023
Proposed change here #35653
potiuk commentedon Nov 15, 2023
Yeah. But it's not the same issue (or at least I believe it's not) - I believe the original issue was connected with SIGALRM not being properly handled by long-running low-level c-code. Catching and ignoring exceptions is a bad programming habit by anyone who run task in a loop from example described hy @hterik. You should generally ignore known exceptions not all of them if you want to add them to the loop in the fashon described here.
We should still make the change to AirflowTaskTimeout inheriting from BaseException to handle this "bad programming" case of course - (we do not want our users to shoot themselves in a foot by not knowing that they are doing something wrong) - but I think Kafka case from #35474 was somethign entirely different (only loosely related). I highly doubt somone in Kafka code handles all exceptions this way - my guess is that SIGALRM was not handled there :)
Taragolis commentedon Nov 15, 2023
To be honest we don't know what the reason in particular this cases. It could be both:
In second case when Airflow task SIGALARM works, we do not control in which place in Main thread code returns
In this case it will break Airflow timeout, and in addition it might breaks something else
In case if handler return in this code block, then change inheritance wouldn't help at all
8 remaining items
potiuk commentedon Nov 29, 2023
So ? Any more concerns :) ?
jscheffl commentedon Dec 31, 2023
The bug report and discussion seems to be a bit stale. Just looking through the PR it looks good and reasonable for me. There might be side effects but we can handle this via a newsfragment I think.
To be on the "safer" side we might put this to a "functional" release, meaning 2.9.0 so that people just upgrading for fixes do catch less "surprises".
Change AirflowTaskTimeout to inherit BaseException
Change AirflowTaskTimeout to inherit BaseException (#35653)