Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent race condition in trying to collect result from DagFileProcessor #11306

Merged

Conversation

ashb
Copy link
Member

@ashb ashb commented Oct 6, 2020

A rare race condition was noticed in the Scheduler HA PR where the
"test_dags_with_system_exit" test would occasionally fail with the
following symptoms:

  • The pipe was "readable" as returned by
    multiprocessing.connection.wait
  • On reading it yielded an EOFError, meaning the other side had closed
    the connection
  • But the process was still alive/running

This previously would result in the Manager process dying with an error.

This PR makes a few changes:

  • It ensures that the pipe is simplex, not duplex (we only ever send one
    data) as this is simpler
  • We ensure that the "other" end of the pipe is correctly closed in both
    parent and child processes. Without this the pipe would be kept open
    (sometimes) until the child process had closed anyway.
  • When we get an EOFError on reading and the process is still alive, we
    give it a few seconds to shut down cleanly, and then kill it.

Read the Pull Request Guidelines for more information.
In case of fundamental code change, 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 UPDATING.md.

A rare race condition was noticed in the Scheduler HA PR where the
"test_dags_with_system_exit" test would occasionally fail with the
following symptoms:

- The pipe was "readable" as returned by
  `multiprocessing.connection.wait`
- On reading it yielded an EOFError, meaning the other side had closed
  the connection
- But the process was still alive/running

This previously would result in the Manager process dying with an error.

This PR makes a few changes:

- It ensures that the pipe is simplex, not duplex (we only ever send one
  data) as this is simpler
- We ensure that the "other" end of the pipe is correctly closed in both
  parent and child processes. Without this the pipe would be kept open
  (sometimes) until the child process had closed anyway.
- When we get an EOFError on reading and the process is still alive, we
  give it a few seconds to shut down cleanly, and then kill it.
@boring-cyborg boring-cyborg bot added the area:Scheduler Scheduler or dag parsing Issues label Oct 6, 2020
@ashb ashb requested review from potiuk and kaxil October 6, 2020 14:21
@ashb
Copy link
Member Author

ashb commented Oct 6, 2020

This is mostly only a problem for dags with system.exit() in it, and is made much much worse by running tests with code coverage enabled.

@ashb
Copy link
Member Author

ashb commented Oct 6, 2020

This was noticed because it started happening a lot more in #10956

@ashb
Copy link
Member Author

ashb commented Oct 6, 2020

With extra logging in scheduler HA this was what we saw:

[2020-10-05 22:39:36,362] {{scheduler_job.py:298}} WARNING - TEST: EOFError received on <DagFileProcessorProcess file_path='/opt/airflow/tests/dags_with_system_exit/a_system_exit.py'>
Traceback (most recent call last):
  File "/opt/airflow/airflow/jobs/scheduler_job.py", line 291, in done
    self._result = self._parent_channel.recv()
  File "/usr/local/lib/python3.8/multiprocessing/connection.py", line 250, in recv
    buf = self._recv_bytes()
  File "/usr/local/lib/python3.8/multiprocessing/connection.py", line 414, in _recv_bytes
    buf = self._recv(4)
  File "/usr/local/lib/python3.8/multiprocessing/connection.py", line 383, in _recv
    raise EOFError
EOFError
[2020-10-05 22:39:36,364] {{scheduler_job.py:307}} WARNING - TEST: process 9709 still alive <DagFileProcessorProcess file_path='/opt/airflow/tests/dags_with_system_exit/a_system_exit.py'>

@ashb
Copy link
Member Author

ashb commented Oct 6, 2020

One failure with exit 137 only. Merging.

@ashb ashb merged commit c803a27 into apache:master Oct 6, 2020
@ashb ashb deleted the race-condition-parsing-process-eoferror branch October 6, 2020 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Scheduler Scheduler or dag parsing Issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants