electron: [Bug]: Electron tries to bind a socket outside the app's container on macOS

Preflight Checklist

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

  1. Take the pre-built binary mas-arm64. Notice this is the mas build, so should play nicely with sandbox entitlement.

  2. Add app code to Electron.app/Contents/Resources/app

  3. code sign with sandbox entitlements as appropriate (add ElectronTeamID, sign helpers, etc)

  4. Launch the app on macOS, notice that a call to app.requestSingleInstanceLock fails 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)

Most upvoted comments

I also ran into this issue with Electron 30 mas build.

  const gotTheLock = app.requestSingleInstanceLock()
  if (!gotTheLock) {
    logMessage('Another instance of the app is already running, exiting...', 'info')
    app.quit()
  }

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:

function safeRequestSingleInstanceLock() {
  if (process.mas) return true; // todo remove when fixed https://github.com/electron/electron/issues/35540
  return app.requestSingleInstanceLock();
}
  • MacOS 13.6 - still has the issue
  • MacOS 14.3.1 - does not have the issue