Skip to content
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

key too long on macos #178

Closed
flaviotordini opened this issue Oct 10, 2023 · 10 comments · Fixed by #180
Closed

key too long on macos #178

flaviotordini opened this issue Oct 10, 2023 · 10 comments · Fixed by #180
Assignees
Labels

Comments

@flaviotordini
Copy link

With Qt 6.6.0 on macOS version 12.3.1 Intel I get this error on startup:

[SingleApplication::SingleApplication] SingleApplication: Unable to create block.
[SingleApplication::abortSafely] SingleApplication:  QSharedMemory::KeyError "QSharedMemoryPrivate::initKey: unable to set key on lock (QSystemSemaphore::handle: key too long)"
@flaviotordini
Copy link
Author

I don't know the details, but in general shouldn't this lib allow a second instance rather than completely failing?

@itay-grudev
Copy link
Owner

Just to clarify, which version of the kl library are you using?

@flaviotordini
Copy link
Author

Ah sorry, the latest version: 3.5.0

@itay-grudev
Copy link
Owner

@jonaski Can you help me with this one, as this is likely related to #177?

@jonaski
Copy link
Collaborator

jonaski commented Oct 12, 2023

It's using shm_open(), this is not a problem on Linux and other unix variants because it uses PATH_MAX, but on macOS the maximum key length is PSHMNAMLEN (31). While the base64 encoded sha256 we use is 44.
See: https://github.com/qt/qtbase/blob/368ea559ebe842500fcad962d02308c7cb2f5632/src/corelib/ipc/qsharedmemory_posix.cpp#L70
I tested the old constructor taking QString instead of QNativeIpcKey, and it's as broken as on Linux (as I explained in the issue), so switching back is not an alternative.
The only simple fix I see now is to use a different base64 encoded string or hash specifically for macOS.

jonaski added a commit to jonaski/SingleApplication that referenced this issue Oct 12, 2023
Maximum key size on macOS is PSHMNAMLEN (31).

Fixes itay-grudev#178
@jonaski jonaski added the bug label Oct 12, 2023
@jonaski jonaski self-assigned this Oct 12, 2023
@jonaski
Copy link
Collaborator

jonaski commented Oct 12, 2023

Unfortunately there seem to be another issue on macOS too, once the application is started and you quit normally, you still can't start it again, so the memory is not released, Qt bug perhaps.

@itay-grudev
Copy link
Owner

itay-grudev commented Oct 12, 2023

@jonaski Does that mean that even with the fix in #180 it won't work?

@jonaski
Copy link
Collaborator

jonaski commented Oct 12, 2023

It solves the issue related to the key size, so the application starts, but there are still issues since the shared memory isn't released.

@itay-grudev
Copy link
Owner

@jonaski I documented it as a known issue in the release notes.

Known issues:

Using Qt 6.6+ on macOS once the application is started and you quit normally, you still can't start it again. This is likely due to a Qt bug. We are still looking for a workaround.

@jonaski
Copy link
Collaborator

jonaski commented Oct 19, 2023

If someone with a mac has a chance to dig into this more, there is a small test project attached to the Qt bug report on https://bugreports.qt.io/browse/QTBUG-111855

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants