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

[fix] Explicitly expire child processes of a Task.Supervisor #1873

Merged
merged 7 commits into from
Sep 27, 2023

Conversation

hannahpurcell
Copy link
Contributor

Child processes of Task.Supervisors do not expire, even if they are meant to be temporary. We need to explicitly end the process if it's running too long. At the moment, the timeout is set for 10s.

@hannahpurcell hannahpurcell requested review from a team, PaulJKim and cmaddox5 and removed request for a team and PaulJKim September 27, 2023 18:08
@github-actions
Copy link

Coverage of commit 07ddc0f

Summary coverage rate:
  lines......: 40.5% (2296 of 5674 lines)
  functions..: 42.1% (1052 of 2501 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/screens_by_alert/memcache.ex                                 | 0.0%     45| 0.0%    12|    -      0
  lib/screens/screens_by_alert/self_refresh_runner.ex                      |15.0%     20|50.0%     6|    -      0
  lib/screens/util.ex                                                      |64.8%     71|72.2%    18|    -      0

Download coverage report

@cmaddox5
Copy link
Contributor

Should the fallback for the DynamicSupervisor we discussed in Slack also be a part of this change? I don't think that fallback can be applied the same way as these, but will be a similar enough change for it to be in scope for this PR.

Copy link
Member

@jzimbel-mbta jzimbel-mbta left a comment

Choose a reason for hiding this comment

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

Good to go, just need that one change to the exit reason in order to force the process to stop.

lib/screens/util.ex Outdated Show resolved Hide resolved
@hannahpurcell
Copy link
Contributor Author

hannahpurcell commented Sep 27, 2023

Should the fallback for the DynamicSupervisor we discussed in Slack also be a part of this change?

@cmaddox5 Sure! I lost sight of that once we found the more realistic bug. I'm having trouble thinking through the erlang process driven logic. Would this just be adding a direct call to :timer.kill_after() right after the start_child line?

@cmaddox5
Copy link
Contributor

Should the fallback for the DynamicSupervisor we discussed in Slack also be a part of this change?

@cmaddox5 Sure! I lost sight of that once we found the more realistic bug. I'm having trouble thinking through the erlang process driven logic. Would this just be adding a direct call to :timer.kill_after() right after the start_child line?

I think it might be safer to get the pid from the return of start_child and call kill_after on that pid. So instead using the timer function before, it would be after in this particular case.

@hannahpurcell
Copy link
Contributor Author

I think it might be safer to get the pid from the return of start_child

Ooohhh of course it returns a pid. Ok ✍️

@github-actions
Copy link

Coverage of commit 2574cee

Summary coverage rate:
  lines......: 40.5% (2296 of 5675 lines)
  functions..: 42.1% (1052 of 2501 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/ol_crowding/dynamic_supervisor.ex                            |40.0%      5|66.7%     3|    -      0
  lib/screens/screens_by_alert/memcache.ex                                 | 0.0%     45| 0.0%    12|    -      0
  lib/screens/screens_by_alert/self_refresh_runner.ex                      |15.0%     20|50.0%     6|    -      0
  lib/screens/util.ex                                                      |64.8%     71|72.2%    18|    -      0

Download coverage report

@@ -48,6 +48,7 @@ defmodule Screens.OlCrowding.DynamicSupervisor do
restart: :transient
}

DynamicSupervisor.start_child(__MODULE__, spec)
{:ok, child_pid} = DynamicSupervisor.start_child(__MODULE__, spec)
Copy link
Contributor

Choose a reason for hiding this comment

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

In order to avoid crashing the app when one of these fails to start, can this be handled in a case instead and if the result is anything but {:ok, child_pid} we can just fail silently (or with a log, up to you on that)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mmmm mmhmm 👍 👍

@github-actions
Copy link

Coverage of commit 2574cee

Summary coverage rate:
  lines......: 40.5% (2296 of 5675 lines)
  functions..: 42.1% (1052 of 2501 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/ol_crowding/dynamic_supervisor.ex                            |40.0%      5|66.7%     3|    -      0
  lib/screens/screens_by_alert/memcache.ex                                 | 0.0%     45| 0.0%    12|    -      0
  lib/screens/screens_by_alert/self_refresh_runner.ex                      |15.0%     20|50.0%     6|    -      0
  lib/screens/util.ex                                                      |64.8%     71|72.2%    18|    -      0

Download coverage report

@hannahpurcell hannahpurcell merged commit e9e4e67 into master Sep 27, 2023
2 checks passed
@hannahpurcell hannahpurcell deleted the hp/expire-old-processes branch September 27, 2023 20:48
@github-actions
Copy link

Coverage of commit db2eac7

Summary coverage rate:
  lines......: 40.4% (2296 of 5678 lines)
  functions..: 42.1% (1052 of 2501 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/ol_crowding/dynamic_supervisor.ex                            |25.0%      8|66.7%     3|    -      0
  lib/screens/ol_crowding/logger.ex                                        | 0.0%     18| 0.0%     4|    -      0
  lib/screens/screens_by_alert/memcache.ex                                 | 0.0%     45| 0.0%    12|    -      0
  lib/screens/screens_by_alert/self_refresh_runner.ex                      |15.0%     20|50.0%     6|    -      0
  lib/screens/util.ex                                                      |64.8%     71|72.2%    18|    -      0

Download coverage report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants