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

File log devices opened by mixlib-log should be closed. #13

Merged
merged 4 commits into from
Aug 3, 2016

Conversation

mhorbul
Copy link
Contributor

@mhorbul mhorbul commented Jan 12, 2016

Ruby does not have a destructor concept so the opened files should be closed explicitly.
The Ruby Logger which is used as a default logger here does not close log devices it opened until #close method is called. When #rest! happens the logger instance gets destroyed but the #close method
is not triggered.
This patch should help to solve the problem described here: chef/chef#3435

def loggers_to_close
loggers_to_close = []
all_loggers.each do |logger|
next unless logdev = logger.instance_variable_get(:"@logdev")

Choose a reason for hiding this comment

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

This seems like a bad idea. Needs a hell of a justification as a comment at least.

@mhorbul
Copy link
Contributor Author

mhorbul commented Feb 2, 2016

I have addeed comment to the code explaining the "bad idea".

Ruby does not have a destructor concept so the opened files should be closed explicitely. The ruby logger which is used as a default logger
here does not close logdevices it opened until #close method is called. When #rest! happens the logger instance gets destroyed but the #close method
is not triggered.
This patch should help to solve the problem described here: chef/chef#3435
@mhorbul
Copy link
Contributor Author

mhorbul commented Mar 18, 2016

I have just rebased branch on latest master and make PR ready to be merged.

@kpumuk
Copy link

kpumuk commented May 25, 2016

👍

@thommay
Copy link
Contributor

thommay commented May 31, 2016

Seems like a reasonable thing to do. @chef/client-core review?

@lamont-granquist
Copy link
Contributor

👍

1 similar comment
@smurawski
Copy link

👍

def close!
# try to close all file loggers
loggers_to_close.each do |l|
l.close rescue nil

Choose a reason for hiding this comment

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

Could we output any rescued errors to stderr? Seems like that would be nice for troubleshooting purposes

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

Successfully merging this pull request may close these issues.

7 participants