New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: create singleton pipename from user & executable #34139
Conversation
I like the temporary solution, maybe we can make this bit more unique. Since it is the first instance that currently creates the named pipe which also turns out to be the // First instance end
uint64_t rand = base::RandUint64();
base::WriteFile(lock_file_path, rand);
std::wstring pipe_name = base::StringPrintf(
L"\\\\.\\pipe\\%s.%lu.%lu.%I64u", program_name_, ::GetCurrentProcessId(),
::GetCurrentThreadId(), rand); // Second instance end
int64_t file_size = 0;
base::GetFileSize(lock_file_path, &file_size);
std::string contents(file_size, '\0');
base::ReadFile(lock_file_path, &contents[0], file_size);
DWORD process_id;
DWORD thread_id = GetWindowThreadProcessId(remote_window_, &process_id);
std::wstring pipe_name = base::StringPrintf(
L"\\\\.\\pipe\\%s.%lu.%lu.%s", program_name_, process_id,
thread_id, contents); |
I’m fine with that, will make the change! One complication with this approach is that pipe names are limited to 256 chars, so I may need to do some abbreviation on items like the program name to make sure we don’t risk exceeding the limit in certain cases - I’ll test and make sure 👍 |
|
4d20d42
to
5ad0f2a
Compare
5ad0f2a
to
7ca6f08
Compare
@deepak1556 @rzhao271 I tried a few different techniques to get the rand number between processes, including writing to the lockfile and creating a new temporary file. It seems that the lockfile (and any other file created/edited) is marked as used by the current process, and permissions aren't granted to edit. To get around this, I reintroduced adding the Let me know if you have any concerns with this approach, happy to try something else! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left minor style comments.
Do we need user name ? Process ID and Thread ID are unique to the system across sessions, so I feel they should suffice for now ? Also, user name might make the pipe name length exceed its limit.
patches/chromium/feat_add_data_transfer_to_requestsingleinstancelock.patch
Outdated
Show resolved
Hide resolved
patches/chromium/feat_add_data_transfer_to_requestsingleinstancelock.patch
Outdated
Show resolved
Hide resolved
patches/chromium/feat_add_data_transfer_to_requestsingleinstancelock.patch
Outdated
Show resolved
Hide resolved
patches/chromium/feat_add_data_transfer_to_requestsingleinstancelock.patch
Outdated
Show resolved
Hide resolved
patches/chromium/feat_add_data_transfer_to_requestsingleinstancelock.patch
Outdated
Show resolved
Hide resolved
Removed user_name after review; using it was also failing consistently on ia32. |
Release Notes Persisted
|
I was unable to backport this PR to "18-x-y" cleanly; |
I have automatically backported this PR to "19-x-y", please check out #34160 |
@VerteDinde has manually backported this PR to "18-x-y", please check out #34161 |
* fix: create singleton pipename from user & executable * fix: use process id & main thread id for pipe name * fix: write rand to file using WIN method * fix: remove file rand, add user_name to pipe * chore: style fixes, shorten program_name & user_name * fix: remove user_name
Description of Change
While investigating #33975, we realized that the problem is not limited to just running the same version of one app in two user sessions, but any two Electron apps using 18 or higher in two user sessions. For example: If a user runs an app using Electron 18+ in one Windows user session, and then run a simple Fiddle that calls
app.requestSingleInstanceLock()
in another Windows user session, the Fiddle crashes.The problem is that named pipes are not session-specific, and thus all Electron apps are trying to access the same named pipe.
This PR adjusts the pipe name, so that it is more unique per executable and per user.
Checklist
npm test
passesRelease Notes
Notes: Fixed a crash on Windows when opening apps in multiple, separate user sessions.