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

Thread leak (and likely memory leak) on Logstash reload #255

Closed
jakelandis opened this issue Dec 14, 2017 · 1 comment
Closed

Thread leak (and likely memory leak) on Logstash reload #255

jakelandis opened this issue Dec 14, 2017 · 1 comment
Assignees

Comments

@jakelandis
Copy link
Contributor

When Logstash pipelines are reloaded via the a configuration change, the rufus jobs thread is not shut down.

Profiling via YourKit (filtering live threads by rufus):
After 1 reload:
image

After another reload:
image

..and another reload:
image

The root cause here is that the rufus stop/shutdown is defined as:

    def shutdown(opt=nil)

      @started_at = nil

      #jobs.each { |j| j.unschedule }
        # provokes https://github.com/jmettraux/rufus-scheduler/issue/98
      @jobs.array.each { |j| j.unschedule }

      @work_queue.clear

      if opt == :wait
        join_all_work_threads
      elsif opt == :kill
        kill_all_work_threads
      end

      unlock
    end

...but we are not sending any options to the shutdown method, so the worker threads never get killed. Any objects associated with that thread would considered to be a memory leak. ...pure subjecture is that JDBC drivers may use thread locals to hold cached state which could lead to a decent memory leak over time and volume

@jakelandis jakelandis self-assigned this Dec 14, 2017
@jakelandis
Copy link
Contributor Author

The fix here is to add the :wait option to the shutdown when reloading a pipeline.

With the fix after a couple reloads:
image

jakelandis added a commit to jakelandis/logstash-input-jdbc that referenced this issue Dec 14, 2017
When a pipeline is reloaded, the rufus stop/shutdown method is called without any arguments. This instructs rufus to leave it's worker threads running. To fully shutdown the rufus worker threads, a :wait or :kill is needed. This change sends the :wait parameter to the shutdown method to ensure that the work thread is stopped. Prior to this change, the thread and all associated memory would stay in the JVM indefinitely.

Fixes logstash-plugins#255
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

No branches or pull requests

1 participant