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

Regression on pid reset to allow task start after heartbeat #17333

Merged
merged 2 commits into from
Aug 3, 2021

Conversation

nmehraein
Copy link
Contributor

@nmehraein nmehraein commented Jul 30, 2021

It's a bug we have found in production in my company.

Here is the bug pattern:

  • The task job is started with a previous run of taskinstance (retry) and an old pid
  • The job take time to start for some reason (db load, system load ...) and not update the pid in database
  • Then the task is killed by heartbeat cause the pid is different from pid in database

It's critical in case of sensors with reschedule mode cause it trigger a fail immediately.

@boring-cyborg
Copy link

boring-cyborg bot commented Jul 30, 2021

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@ephraimbuddy
Copy link
Contributor

Do you have a dag that could be used to reproduce this behaviour?

@nmehraein
Copy link
Contributor Author

nmehraein commented Jul 30, 2021

Do you have a dag that could be used to reproduce this behaviour?

@ephraimbuddy IMO it's not a bug that can be reproduced in a simply dag cause it not concern task execution code but task runner.
To reproduce we have to slowdown the task starting process:

If the starting process take more time than heartbeat (5s default), and it's not the first TI run, the problem occur.

I don't know if you have another idea to reproduce that in a dag ?

In my case, it occur more specifically in production at night, when the scheduler process our data of last day, and lot of task is running in parallel that generate load on our servers and our airflow db.

@nmehraein
Copy link
Contributor Author

Maybe our first log with that error from airflow can help

[2021-07-18 03:09:34,879] {{logging_mixin.py:104}} INFO - Running <TaskInstance: task_name 2021-07-17T00:00:00+00:00 [running]> on host xxxxxxxxxxx
[2021-07-18 03:09:34,885] {{local_task_job.py:195}} WARNING - Recorded pid 4932 does not match the current pid 14922
[2021-07-18 03:09:34,893] {{process_utils.py:100}} INFO - Sending Signals.SIGTERM to GPID 14922
[2021-07-18 03:09:34,900] {{process_utils.py:66}} INFO - Process psutil.Process(pid=14922, status='terminated', exitcode=<Negsignal.SIGTERM: -15>, started='03:09:29') (14922) terminated with exit code Negsignal.SIGTERM

@@ -1111,6 +1111,7 @@ def check_and_change_state_before_execution(
if not test_mode:
session.add(Log(State.RUNNING, self))
self.state = State.RUNNING
self.pid = None
Copy link
Member

@jedcunningham jedcunningham Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be up with lines 1043-1044 instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i put it back on line where it was in 2.0 , but I'm going to push a commit to put it next to the hostname which I think is a good place too. https://github.com/apache/airflow/blob/2.0.2/airflow/models/taskinstance.py#L1076

Copy link
Contributor

@ephraimbuddy ephraimbuddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite understandable(makes sense to me). Let's wait for @ashb to also take a look

@ephraimbuddy ephraimbuddy added the full tests needed We need to run full set of tests for this PR to merge label Aug 2, 2021
@ephraimbuddy ephraimbuddy reopened this Aug 2, 2021
@nmehraein nmehraein force-pushed the fix_pid_reset_healtcheck_bug branch from 1eaa20b to 428cc76 Compare August 2, 2021 10:32
tests/jobs/test_local_task_job.py Outdated Show resolved Hide resolved
@ashb
Copy link
Member

ashb commented Aug 3, 2021

LGTM @ephraimbuddy

@ephraimbuddy ephraimbuddy merged commit ed99eaa into apache:main Aug 3, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 3, 2021

Awesome work, congrats on your first merged pull request!

@laserpedro
Copy link

I incorporated the change https://github.com/apache/airflow/blob/2.0.2/airflow/models/taskinstance.py#L1076 and I am still getting the error ....

kaxil pushed a commit that referenced this pull request Sep 11, 2021
Regression on PID reset to allow task start after heartbeat

Co-authored-by: Nicolas MEHRAEIN <nicolas.mehraein@adevinta.com>
(cherry picked from commit ed99eaa)
@jedcunningham jedcunningham added this to the Airflow 2.1.4 milestone Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full tests needed We need to run full set of tests for this PR to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants