SingleInstanceLock API in depth

Hey guys, I need some help…
TL:DR

  1. I want to make sure the SingleInstanceLock API is super robust for windows.
  2. 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 :slightly_smiling_face:

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:

  1. Did I get it right? Is it really 100% safe and protected against these “extreme” races as I call them?
  2. 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.

1 Like

Google isn’t giving me any information about what that API call does, but the process_singleton_win.cc code is the same as you find in the Chromium source. So I would expect the behavior to be the same.

By your answer I’m not sure I was clear enough in my question.
This is the comment that bothers me:

// We have to make sure there is no Chrome instance running on another
// machine that uses the same profile.

It is written above the handling of a lock file.
Do you think I should ask this question in a chromium forum? Do you happen to know where I should post my question and point me out there?

Thanks

Yes, because those are the people who will fully understand what that code does.

1 Like