Repository navigation
Description
Apache Airflow version
main (development)
If "Other Airflow 2 version" selected, which one?
No response
What happened?
I am not able to reproduce this consistently but I noticed when there is an error response of 4xx/5xx from the API then ServerResponseError which inherits from httpx.HTTPStatusError is raised. The object httpx.HTTPStatusError is not pickleable and has an open PR. Since request and response are keyword only arguments this causes the scheduler to crash with below stacktrace trying to unpickle. The exception seems to be raised from raise_on_4xx_5xx function.
encode/httpx#3108
https://docs.python.org/3/library/pickle.html#object.__getnewargs_ex__
You should implement this method if the new() method of your class requires keyword-only arguments. Otherwise, it is recommended for compatibility to implement getnewargs().
Traceback
[2025-03-11T18:20:15.560+0530] {scheduler_job_runner.py:939} ERROR - Exception when executing SchedulerJob._run_scheduler_loop
Traceback (most recent call last):
File "/home/karthikeyan/stuff/python/airflow/airflow/jobs/scheduler_job_runner.py", line 935, in _execute
self._run_scheduler_loop()
File "/home/karthikeyan/stuff/python/airflow/airflow/jobs/scheduler_job_runner.py", line 1067, in _run_scheduler_loop
executor.heartbeat()
File "/home/karthikeyan/stuff/python/airflow/airflow/traces/tracer.py", line 54, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/karthikeyan/stuff/python/airflow/airflow/executors/base_executor.py", line 254, in heartbeat
self.sync()
File "/home/karthikeyan/stuff/python/airflow/airflow/executors/local_executor.py", line 210, in sync
self._read_results()
File "/home/karthikeyan/stuff/python/airflow/airflow/executors/local_executor.py", line 215, in _read_results
key, state, exc = self.result_queue.get()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/multiprocessing/queues.py", line 367, in get
return _ForkingPickler.loads(res)
^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ServerResponseError.__init__() missing 2 required keyword-only arguments: 'request' and 'response'
What you think should happen instead?
No response
How to reproduce
API errors to task-sdk trigger this but I don't have a concrete scenario to reproduce this consistently.
Operating System
Ubuntu 20.04
Versions of Apache Airflow Providers
No response
Deployment
Virtualenv installation
Deployment details
No response
Anything else?
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
tirkarthi commentedon Mar 18, 2025
cc: @ashb @amoghrajesh @kaxil
amoghrajesh commentedon Mar 18, 2025
@tirkarthi could you maybe attach your dag in here too? Hard to say this way
tirkarthi commentedon Mar 18, 2025
Sorry, I don't have a dag that consistently reproduces this but this happens when an error response is received from the API with status code as 4xx/5xx in the response code like validation error or the API server is not able to connect to the database scenarios which shouldn't cause the scheduler to crash since the httpx error response cannot be unpickled. Let me see if I can get some steps for this scenario.
tirkarthi commentedon Mar 18, 2025
example_xcomexample dag with a manual logical date.delete from dag_run where dag_id="example_xcom";example_xcomexample dag with the same manual logical date.This might not be the ideal way but the issue is that any type of such validation error shouldn't crash the scheduler and once the scheduler enters this state restarting again tries the same API call which will result in validation error and crashes the scheduler.
amoghrajesh commentedon Mar 22, 2025
@tirkarthi i tried reproducing this with the steps you suggested, cannot reproduce again. Could you please try again on latest main?
tirkarthi commentedon Mar 22, 2025
@amoghrajesh I am unable to reproduce it too :( . It depends on the API server returning 4xx/5xx response for some reason like validation error or internal server error. The crux of the issue is as below that
ServerResponseErrorcannot be pickled due to keyword arguments whenever there is a 4xx/5xx response from the API server.7 remaining items
Fix Worker crash on API Server Error (apache#48517)
Fix Worker crash on API Server Error (#48517)
tomaszstepinvest commentedon Aug 25, 2025
It should not be closed. The same error for 3.0.4
pyenv shell 3.11 && python -m venv .venv && source .venv/bin/activate && airflow standalone
potiuk commentedon Aug 25, 2025
Please open new issue if you see it @tomaszstepinvest -> even if that issue might look similar it's possibly a different one and without sharing any details about your case it's impossible to say.
Make sure to install airflow with constraints as described in our documentation however. This might be your issue.
Fix Worker crash on API Server Error (#48517)
Fix Worker crash on API Server Error (#48517)
Fix Worker crash on API Server Error (#48517)
Fix Worker crash on API Server Error (#48517)
Fix Worker crash on API Server Error (#48517)
Fix Worker crash on API Server Error (#48517)