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

Generate unique, temporary names for socket files in a more robust way. #6

Merged
merged 4 commits into from
Jan 24, 2013

Conversation

joeyAghion
Copy link
Contributor

The Thin back-end generates a default socket filename by calling Tempfile.open:

Tempfile.open 'thin' do |file|
  return file.path
end

However, this does more than generate a nicely unique name; it actually creates the file then frees it to be deleted at the close of the block. Garbage collection will delete it next time it runs. (Note that, as far as we know, this hasn't dinged us in production. Maybe the fact that the proxy process has started writing to the file prevents the delete?)

This commit adds a Utils.tmp_filename helper for this purpose instead. It's based on ruby 1.9's Dir::Tmpname.make_tmpname. New specs assert that the generated filename doesn't exist before server start, and that later garbage-collection doesn't delete the socket.

@dblock
Copy link
Owner

dblock commented Jan 24, 2013

I feel that Utils is a not great namespace for tmp filename generation. How about a matching Heroku::Forward::Dir::Tmpname ?

Next Release
============

* Improve generation of temporary filename for socket - [@joeyAghion](https://github.com/joeyAghion)
Copy link
Owner

Choose a reason for hiding this comment

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

You're missing a dot (.) at the end of this sentence ;)

@joeyAghion
Copy link
Contributor Author

As discussed, since the new helper doesn't match the stdlib's interface, I think a matching name and namespace would be confusing. But I moved it into Utils::Dir for extra neatness.

@joeyAghion
Copy link
Contributor Author

And, finally, I added a forward directory under spec/lib/heroku and reorganized the files within so that the spec directory matches the source files' organization.

dblock added a commit that referenced this pull request Jan 24, 2013
Generate unique, temporary names for socket files in a more robust way.
@dblock dblock merged commit 34d22f3 into dblock:master Jan 24, 2013
@joeyAghion
Copy link
Contributor Author

Follow-up: I confirmed that this issue was actually plaguing my local environment. It manifests as the socket file disappearing after a few minutes of up-time, with the proxy outputting:

no connection, 100 retries left
no connection, 99 retries left
no connection, 98 retries left
...

This fix appears to address the issue successfully. Cheers!

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.

2 participants