Multiple Mounts Bug
AbdullahAli opened this issue · 2 comments
Hey Julien,
I was testing this gem with my practice/tutorial projects and I noticed an issue.
If the shell/terminal was not closed by sending the mrd command a proper terminate signal, then the device stays mounted. If you try to open another terminal and try to start the mrd command again, it will complain with errors (which, indicate that the device already exists), as follow:
Created Ramdisk at /dev/disk2
Formatted Ramdisk at /dev/disk2
Mounted Ramdisk at /Volumes/MySQLRAMDisk 1
/bin/mysqld: Too many arguments (first extra is '1').
Use --verbose --help to get a list of available options
130827 22:54:16 [ERROR] Aborting
130827 22:54:16 [Note] ./bin/mysqld: Shutdown complete
Ejecting RAM disk
/Users/Abdullah/.rvm/gems/ruby-1.9.3-p194/gems/mrd-0.0.6/bin/mrd:48:in `block in run!': pid 1036 exit 1 .(App::Runner::CommandError)
from /Users/Abdullah/.rvm/gems/ruby-1.9.3-p194/gems/mrd-0.0.6/bin/mrd:47:in `tap'
from /Users/Abdullah/.rvm/gems/ruby-1.9.3-p194/gems/mrd-0.0.6/bin/mrd:47:in `run!'
from /Users/Abdullah/.rvm/gems/ruby-1.9.3-p194/gems/mrd-0.0.6/bin/mrd:158:in `start'
from /Users/Abdullah/.rvm/gems/ruby-1.9.3-p194/gems/mrd-0.0.6/bin/mrd:263:in `child_main'
from /Users/Abdullah/.rvm/gems/ruby-1.9.3-p194/gems/mrd-0.0.6/bin/mrd:246:in `main'
from /Users/Abdullah/.rvm/gems/ruby-1.9.3-p194/gems/mrd-0.0.6/bin/mrd:322:in `<top (required)>'
To replicate:
- go to project
- run mrd
- close the terminal by clicking the "X" button - not by CTRL-C
- open a new shell session
- go to the same project
- run mrd
I think this is a two part issue:
- Are multiple mounts allowed? if so, then maybe we would need a unique identifier for each of the mounts, like the object_id/timestamp, maybe something like:
def mount
…
run!("diskutil erasevolume HFS+ MySQLRAMDisk-#{@device.object_id} #{@device}")
…
end
- We need to clean left over mounted devices, which did not get unmounted properly:
I think this can be fixed by cleaning up every time BEFORE mounting the device. However, this clean up needs to take into consideration that the above could have been done multiple times (ie the same device has been mounted N times, from different terminal sessions). Maybe 'grep'ing on the mounted devices and unmounting each?
Let me know your thoughts,
Regards,
Abdullah
@mezis I am not sure if this has been assigned properly
Hi @AbdullahAli, this is indeed an issue. mrd
will normally shut down properly even if you close the window (as opposed to pressing ^C), since the process then receives a SIGHUP, which is correctly caught.
What you bumped into is two separate things:
- a race condition. If you restart
mrd
too soon after closing the window (while it's still shutting down in the background), it'll blow up. - a (missing) feature.
mrd
doesn't know how to handle multiple, concurrent instances.
I'll wrap my head around it and try to address both.