Skip to content

Multiproc files not cleaned up if worker gets segfault/oom/... #115

Closed

Description

@jonashaag

In multiproc mode, if one of the gunicorn workers gets killed because of a segfault or out-of-memory situation, it doesn't get a chance to clean up its .db files. These files are thus left in the multiproc folder, distorting the metrics.

Maybe this can be solved by moving the cleanup hook into the gunicorn "master" process. My suggestion is to solve this in the Python client instead, by deleting all .db files with dead PIDs before aggregating the metrics.

Activity

  1. added a commit that references this issue on Nov 11, 2016
    139785e
  2. brian-brazil commented on Nov 11, 2016

    @brian-brazil
    Contributor

    This is by design. It's incorrect to delete the files while the process is still running, and it's expected that the user will clean them up during restarts.

  3. jonashaag commented on Nov 11, 2016

    @jonashaag
    Author

    In a segfault or OOM situation the process isn't running anymore. The gunicorn cleanup example in the documentation is incomplete; it doesn't cover the "Python crashes" situation.

  4. brian-brazil commented on Nov 11, 2016

    @brian-brazil
    Contributor

    I had thought worker_exit was handled in the master, presumably by doing a wait. Is that not the case?

  5. jonashaag commented on Nov 11, 2016

    @jonashaag
    Author
  6. brian-brazil commented on Nov 11, 2016

    @brian-brazil
    Contributor

    Hmm, can we get a feature request in to be able to hook into reap_workers?

  7. jonashaag commented on Nov 11, 2016

    @jonashaag
    Author

    This would only work for gunicorn though. What do you think about my suggestion, which is a much more general solution to the problem?

  8. brian-brazil commented on Nov 11, 2016

    @brian-brazil
    Contributor

    You're presuming that pids are never reused, and deleting too many tiles. A solution based on wait is the proper solution.

  9. jonashaag commented on Nov 11, 2016

    @jonashaag
    Author

    So I'm not sure about for how long PIDs aren't reused, but I doubt it's quicker than the usual Prometheus scrape interval. In addition we could check if the PIDs are child processes of the aggregating parent process. What are the chances that a new worker process with the same PID is spawned within the scrape interval?

    Maybe we should incorporate both solutions.

  10. brian-brazil commented on Nov 11, 2016

    @brian-brazil
    Contributor

    So I'm not sure about for how long PIDs aren't reused, but I doubt it's quicker than the usual Prometheus scrape interval.

    That depends on how many processes are being spawned, and how the pid allocation strategy is.

    In addition we could check if the PIDs are child processes of the aggregating parent process.

    We don't actually know that the values are pids. They could be worker IDs (indeed it's better if they are, less label churn).

  11. jonashaag commented on Nov 12, 2016

    @jonashaag
    Author

    We don't actually know that the values are pids. They could be worker IDs (indeed it's better if they are, less label churn).

    I see. To me this is a prime example of leaky abstraction that has to be improved.

    Is your final suggestion to hook into reap_workers, i.e. make the forking process's responsibility to deal with all sorts of worker exits?

  12. brian-brazil commented on Nov 12, 2016

    @brian-brazil
    Contributor

    Yes. The only sane way to handle this it to make it the parent process's responsibility.

  13. Deimos commented on Mar 6, 2017

    @Deimos

    @jonashaag @brian-brazil Sorry for the ping if you were already aware, but I just wanted to make sure you knew that gunicorn 19.7.0 was released on March 1 with the child_exit() callback added, so this should be possible to implement now: http://docs.gunicorn.org/en/latest/news.html#id1

  14. brian-brazil commented on Mar 17, 2017

    @brian-brazil
    Contributor

    Gunicorn has the required feature now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions