Repository navigation
Fix Worker crash on API Server Error - #48517
Conversation
ashb
left a comment
There was a problem hiding this comment.
I mean okay, but what is actually using pickle in our path?
What is trying to pickle the exception in the first place
It is coming from Local Executor, specifically the following block: airflow/airflow-core/src/airflow/executors/local_executor.py Lines 91 to 97 in 831f12a When a task fails with an exception, the exception is put into the r Later, in _read_results, the executor tries to read from this queue, and it fails!!: airflow/airflow-core/src/airflow/executors/local_executor.py Lines 208 to 210 in 831f12a |
closes apache#47873 closes apache#48503
|
This should hold us for now, I have another fix in mind -- just a little more involved |
amoghrajesh
left a comment
There was a problem hiding this comment.
Goodness, good catch!
Follow-up of apache#48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by apache#48517. This PR improves upon it and propogates the API server error in the task UI and fails the task.
Follow-up of #48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by #48517. This PR improves upon it and propogates the API server error in the task UI and fails the task.
) Follow-up of apache#48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by apache#48517. This PR improves upon it and propogates the API server error in the task UI and fails the task.
Follow-up of apache/airflow#48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by apache/airflow#48517. This PR improves upon it and propogates the API server error in the task UI and fails the task. GitOrigin-RevId: 02d251c6002f524c9a86da80a44687982c262698
Follow-up of apache/airflow#48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by apache/airflow#48517. This PR improves upon it and propogates the API server error in the task UI and fails the task. GitOrigin-RevId: 02d251c6002f524c9a86da80a44687982c262698
Follow-up of apache/airflow#48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by apache/airflow#48517. This PR improves upon it and propogates the API server error in the task UI and fails the task. GitOrigin-RevId: 02d251c6002f524c9a86da80a44687982c262698
Follow-up of apache/airflow#48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by apache/airflow#48517. This PR improves upon it and propogates the API server error in the task UI and fails the task. GitOrigin-RevId: 02d251c6002f524c9a86da80a44687982c262698
| # def test_server_response_error_pickling(): | ||
| # """Test that ServerResponseError can be pickled and unpickled.""" | ||
| # def handle_request(request: httpx.Request) -> httpx.Response: | ||
| # return httpx.Response( | ||
| # status_code=400, | ||
| # request=request, | ||
| # json={"detail": {"message": "Invalid input"}}, | ||
| # ) | ||
| # | ||
| # client = make_client(transport=httpx.MockTransport(handle_request)) | ||
| # | ||
| # # Create an error by making a request that will fail | ||
| # with pytest.raises(ServerResponseError) as exc_info: | ||
| # client.get("http://fake-url-for-testing") | ||
| # | ||
| # err = exc_info.value | ||
| # | ||
| # # Pickle and unpickle | ||
| # pickled = pickle.dumps(err) | ||
| # unpickled = pickle.loads(pickled) | ||
| # | ||
| # assert isinstance(unpickled, ServerResponseError) | ||
| # | ||
| # # Error message from response | ||
| # assert unpickled.response.json() == {"detail": {"message": "Invalid input"}} | ||
| # assert unpickled.detail == {"detail": {"message": "Invalid input"}} | ||
| # assert unpickled.response.status_code == 400 | ||
| # assert unpickled.request.url == "http://fake-url-for-testing" |
|
Has this already been released in a production release? I'm getting the same error running Airflow 3.2.1 |
Follow-up of apache/airflow#48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by apache/airflow#48517. This PR improves upon it and propogates the API server error in the task UI and fails the task. GitOrigin-RevId: 02d251c6002f524c9a86da80a44687982c262698
Follow-up of apache/airflow#48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by apache/airflow#48517. This PR improves upon it and propogates the API server error in the task UI and fails the task. GitOrigin-RevId: 02d251c6002f524c9a86da80a44687982c262698
get_json_error() only wraps 400-599 responses in the picklable ServerResponseError (it needs a custom __reduce__ because plain httpx.HTTPStatusError requires keyword-only request/response arguments pickle's default reconstruction can't supply -- see apache#47873, fixed for that path by apache#48517). A 3xx response -- e.g. a corporate proxy in front of the API server returning a redirect -- falls outside that range, so httpx.Response.raise_for_status() raises the bare, unpicklable httpx.HTTPStatusError instead. That bare exception crashes the scheduler once it crosses a multiprocessing boundary: LocalExecutor.result_queue is a multiprocessing.Queue, and unpickling the exception on the scheduler side fails with the exact "missing keyword-only arguments" TypeError apache#47873 first reported, just triggered by a redirect instead of a JSON error body. _raise_for_status_picklable() now wraps anything raise_for_status() raises outside the 400-599 range in a ServerResponseError too, while leaving in-range errors that from_response() couldn't parse a JSON detail from exactly as before.
Follow-up of apache/airflow#48517 Currently, when a task fails due to API Server error, the task logs shows nothing, and the task continues running. It also leads to the pickling issue on LocalExecutor that was fixed by apache/airflow#48517. This PR improves upon it and propogates the API server error in the task UI and fails the task. GitOrigin-RevId: 02d251c6002f524c9a86da80a44687982c262698
closes #47873
closes #48503
The error comes from
LocalExecutor, specifically the following block:airflow/airflow-core/src/airflow/executors/local_executor.py
Lines 91 to 97 in 831f12a
When a task fails with an exception, the exception is put into the
result_queueas part of a tuple with the task key and state.Later, in _read_results, the executor tries to read from this queue, and it fails!!:
airflow/airflow-core/src/airflow/executors/local_executor.py
Lines 208 to 210 in 831f12a
Before:
The scheduler with
LocalExecutorfails and exits with the following error. This was becauseServerResponseErrorisn't picklable andhttpxmaintainers haven't merged encode/httpx#3108.The task stays in
runningstate:
After:
The worker continues execution and marks the current task as failed.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.