Hey guys, I need some help…
TL:DR
- I want to make sure the SingleInstanceLock API is super robust for windows.
- I found a suspicious comment in the c++ code that makes me think this api block multiple instances of the app for the same user across a managed network and not only on the specific PC.
Thanks
I’m in need of a robust “single instance” functionality for windows.
I found the new SingleInstanceLock API which replaced the old makeSingleInstance API.
I deep dived into the c++ code to understand how it works and make sure it is completely protected against “extreme” races between 2 or more electron app instances.
It looks like it is protected by at least 3 different objects, the final one being a mutex, so it seems safe.
For reference, the files I looked at are: atom_api_app.cc and “process_singleton_win.cc”
I have 2 questions regarding the logic implemented in this code:
- Did I get it right? Is it really 100% safe and protected against these “extreme” races as I call them?
- In the process_singleton_win.cc file, in the ProcessSingleton::Create() method, I found the following code:
remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_);
if (!remote_window_) {
// We have to make sure there is no Chrome instance running on another
// machine that uses the same profile.
base::FilePath lock_file_path = user_data_dir_.AppendASCII(kLockfile);
lock_file_ =
::CreateFile(lock_file_path.value().c_str(), GENERIC_WRITE,
FILE_SHARE_READ, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL);
Notice the comment - It frightens me a bit…
It seems like it says that if a user is connected to multiple computers on the same network at the same time, he won’t be able to start the app. Is that true?
Obviously if that is true, I need some guidance for how to use this SingleInstanceLock API in a machine-wide manner, and not a managed network - wide manner.
Thanks.