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

Don't fallback on tmp if it's not writable #158

Merged
merged 1 commit into from
Sep 22, 2016

Conversation

tombruijn
Copy link
Member

Currently if the set log path, or the project path, are not writable we
always fallback on the /tmp/appsignal.log fallback path. This breaks
if the fallback path is also not writable.

This change adds a permission check on the /tmp fallback path and
returns nil if no suitable log path can be found.

Update test to handle more cases.


This should fix problem 1 in #153

Copy link
Member Author

@tombruijn tombruijn left a comment

Choose a reason for hiding this comment

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

Found another bug :(

@tombruijn
Copy link
Member Author

tombruijn commented Sep 20, 2016

@jeffkreeftmeijer and @thijsc please re-review

I now check the /tmp dir writability, not /tmp/appsignal.log, which might not exist yet. Saved the path in a constant so it can be more easily modified in a spec.

Changed $stderr to $stdout, because that's what we use most of the time.

I'll squash these commits after approval

I'll send in another PR for changes to appsignal.rb in #start_logger for when the actual file {project_path}/log/appsignal.log or {SYSTEM_TMP_DIR}/appsignal.log} doesn't exist or does exist and is not writable.

end
rescue Errno::ENOENT
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to reinstate the rescue here to make sure we print a useful error message when we can't write to the file for any other reason than we've just checked?

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed it because I'm not quite sure what can cause an Errno::ENOENT to be thrown here.

File.writable? doesn't throw it for a file that doesn't exist or is not writable.

Copy link
Member

Choose a reason for hiding this comment

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

You're right. Errno::ENOENT doesn't seem to get raised when calling#writable?, so I'm not sure why this was here in the first place. Could we catch this when trying to write to the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jeffkreeftmeijer that's what PR #160 is for 😄

end
rescue Errno::ENOENT
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -90,13 +91,18 @@ def []=(key, value)

def log_file_path
path = config_hash[:log_path] || root_path
if path && File.writable?(path)
File.join(File.realpath(path), 'appsignal.log')
return File.join(path, 'appsignal.log') if path && File.writable?(path)
Copy link
Member

Choose a reason for hiding this comment

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

The File.realpath call is essential because it allows us to break out Capistrano style release directories to shared directories. Without this an agent that survives enough deploys to live through a cleanup dies.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah right, readded the case and added some tests for it too :)

@tombruijn
Copy link
Member Author

Ready for re-review

Note: I'd like to squash these commits on merge, no need to remove the realpath check only to add it back two commits later

@thijsc
Copy link
Member

thijsc commented Sep 22, 2016

Indeed. Especially in the gem I only want commits in the history that are actually released.

Currently if the set log path, or the project path, are not writable we
always fallback on the `/tmp/appsignal.log` fallback path. This breaks
if the fallback path is also not writable.

This change adds a permission check on the /tmp fallback path and
returns `nil` if no suitable log path can be found.

Update test to handle more cases.
@tombruijn tombruijn merged commit 862fb08 into master Sep 22, 2016
@tombruijn tombruijn deleted the log_file_path-improvements branch September 22, 2016 14:56
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.

None yet

3 participants