Skip to content

Conversation

hanazuki
Copy link
Contributor

This patch resolves #376 a problem with multi-user environment.

On many traditional *nix systems all the users on the same machine share a single global /tmp.
If two users on such a system run spring at the same time, the first user's spring process
creates /tmp/spring and stores a pidfile and a socket within the directory.
The second users process will then try to store its pidfile within /tmp/spring, but it fails
since the directory is owned by another user and (usually) not writable to non-owners.

This patch resolves this problem by making the temporary directory path used by spring
contain the UID of the running process.
If you are the user with UID of 1000, your spring processes will create the directory
$TMPDIR/spring-1000 and store everything therein.


Two other solutions are suggested on the issue #376

  1. Use tmp directory inside the Rails application's tree
  2. Make /tmp/spring world-writable

I think both of them have some problem

  • As pointed out in the issue, Rails tmp may reside within a filesystem without domain socket support.
  • Making /tmp/spring is not safe --- Let other users delete your socket.

AFAIK, Emacs and tmux takes this solution with process's UID to store per-user server socket in the global /tmp directory.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @grosser (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@grosser
Copy link
Collaborator

grosser commented Nov 14, 2015

that means atm you cannot run 2 springs at them same time either ? -> should we add the File.dirname(Rails.root) too ?

@grosser
Copy link
Collaborator

grosser commented Nov 14, 2015

ahh ... all the others add application_id to the path ...
I'd say 👍 ... but better have @rafaelfranca + @jonleighton take another look ...

@jonleighton
Copy link
Member

👍 from me.

@grosser
Copy link
Collaborator

grosser commented Nov 28, 2015

@hanazuki can you rebase ?

@hanazuki
Copy link
Contributor Author

@grosser Sure, I will.

This patch resolves rails#376 a problem with multi-user environment.

On many traditional *nix systems all the users on the same machine share a single global `/tmp`.
If two users on such a system run spring at the same time, the first user's spring process
creates `/tmp/spring` and stores a pidfile and a socket within the directory.
The second users process will then try to store its pidfile within `/tmp/spring`, but it fails
since the directory is owned by another user and (usually) not writable to non-owners.

This patch resolves this problem by making the temporary directory path used by spring
contain the UID of the running process.
If you are the user with UID of 1000, your spring processes will create the directory
`$TMPDIR/spring-1000` and store everything therein.
@hanazuki
Copy link
Contributor Author

Rebased on the current master

grosser added a commit that referenced this pull request Nov 30, 2015
Make the temporary directory path contain uid of the process
@grosser grosser merged commit 1b045fb into rails:master Nov 30, 2015
@grosser
Copy link
Collaborator

grosser commented Nov 30, 2015

1.5.0 is out!

@hanazuki
Copy link
Contributor Author

hanazuki commented Dec 1, 2015

Thanks a lot!

@hanazuki hanazuki deleted the tmp-uid branch December 1, 2015 00:57
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.

Support for multiuser enviroment
4 participants