Visitar URL original
Regression on pid reset to allow task start after heartbeat by nmehraein · Pull Request #17333 · apache/airflow · GitHub
Skip to content

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

Merged
ephraimbuddy merged 2 commits into
apache:mainfrom
nmehraein:fix_pid_reset_healtcheck_bug
Aug 3, 2021
Merged

ephraimbuddy merged 2 commits into
apache:mainfrom
nmehraein:fix_pid_reset_healtcheck_bug

Conversation

@nmehraein

@nmehraein nmehraein commented Jul 30, 2021 •

Copy link
Copy Markdown
Contributor

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.

@nmehraein
nmehraein requested review from XD-DENG, ashb and kaxil as code owners July 30, 2021 07:56
@boring-cyborg

boring-cyborg Bot commented Jul 30, 2021

Copy link
Copy Markdown

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
Copy Markdown
Contributor

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

@nmehraein

nmehraein commented Jul 30, 2021 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

Comment thread airflow/models/taskinstance.py Outdated

@jedcunningham jedcunningham Jul 30, 2021 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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

@ephraimbuddy ephraimbuddy left a comment •

Copy link
Copy Markdown
Contributor

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
Comment thread tests/jobs/test_local_task_job.py Resolved
@nmehraein
nmehraein force-pushed the fix_pid_reset_healtcheck_bug branch from 4f6b399 to 428cc76 Compare August 2, 2021 14:27
@nmehraein
nmehraein requested a review from ephraimbuddy August 2, 2021 14:52
@ashb

ashb commented Aug 3, 2021

Copy link
Copy Markdown
Member

LGTM @ephraimbuddy

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

boring-cyborg Bot commented Aug 3, 2021

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request!

@laserpedro

Copy link
Copy Markdown

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