electron: [Bug]: Electron tries to bind a socket outside the app's container on macOS
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
19.0.6
What operating system are you using?
macOS
Operating System Version
macOS
What arch are you using?
arm64 (including Apple Silicon)
Last Known Working Electron version
No response
Expected Behavior
I expected the socket to be binded to a file descriptor inside the app’s container. I also expected the app to launch correctly.
Actual Behavior
-
Take the pre-built binary
mas-arm64. Notice this is themasbuild, so should play nicely with sandbox entitlement. -
Add app code to
Electron.app/Contents/Resources/app -
code sign with sandbox entitlements as appropriate (add
ElectronTeamID, sign helpers, etc) -
Launch the app on macOS, notice that a call to
app.requestSingleInstanceLockfails with the error code :
process_singleton_posix.cc(1184)] Failed to bind() /var/folders/s2/j0z79krx43qgmt8l71r95_zc0000gn/T/com.electron.logseq/S/SingletonSocket: Operation not permitted (1)
This means requestSingleInstanceLock is trying to bind a socket outside the app’s container. I would not expect that from the mas build.
Testcase Gist URL
No response
Additional Information
If I do all the same thing, but remove the com.apple.security.app-sandbox entitlement, then it all works correctly.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 19 (10 by maintainers)
I also ran into this issue with Electron 30 mas build.
On Sonoma, this works, but on older MacOS versions it always returns falsy even though there is no other instance. I guess I just disable this logic for MacOS.
Ok I found out why it exits with error code 0, because my code calls
if (!app.requestSingleInstanceLock()) app.quit()(duhh)So my workaround to this problem is to wrap the function and don’t call it for mas builds: