WLBF / single-instance

A rust library for single instance application.
MIT License
34 stars 8 forks source link

False positive determining if application is already running #11

Closed marcbrevoort-cyberhive closed 3 years ago

marcbrevoort-cyberhive commented 3 years ago

There is an issue with this library where it may prevent an application from running when it actually isn't running yet.

For instance, I might try to run the application and single instance triggers, claiming it is "already running"; I then realise that my editor is editing a file with a similar name to the application. When quitting the editor, the single instance crate no longer blocks and allows me to run the application.

I have not viewed the source but this suggests SingleInstance does the equivalent of a "grep" on the process list, disregarding where the application name string occurs in the list (as program name or as another command line argument), leading to false positives.

It would be more reliable to create a mutex, for instance a file with a deterministic name and keep a file lock on it for the duration of the run, so that a second instance would fail to acquire this lock until the first application has quit or crashed.

WLBF commented 3 years ago

I guess your problem is cause by not set SingleInstance argument properly. On macos SingleInstance will create a temp file and add flock on it, you can control the file path by pass str argument to constructor. Or just simply avoid open that temp file with editor.