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
SingleApplication blocks application on macOS with Apple M1 #136
Comments
I believe I read something, somewhere about a similar issue on apps running on M1s. Something about shared memory... Let me try to find it. |
From what I can see, there shouldn't be an issue with shared memory on M1 MacOS. But without having access to M1 hardware it would be hard for me to reproduce it. Any ideas? Do you have access to M1 hardware? |
One way would be to add an exception, but I'd rather investigate the real cause of the issue. For all I know it may be a Qt bug in the underlying implementation.
SingleApplication/singleapplication.cpp Lines 44 to 49 in d5b3852
|
Yeah, I compiled my project on M1 mac mini(Version 11.2), and the Qt version is 5.15.2. I don't have too much to compile other versions and currently we don't have any plans to migrate to Qt 6. |
I need assistance for this as I currently don't have access to an M1 machine and cannot look into it in dept. But my guess is there is some Qt issue on that platform. |
Hey, I'm happy to help if I can - I'm using SingleApplication for one of my projects and I'm working solely on an M1 MacBook Air. For a starter I'm not observing the problem with using SingleApplication with However if I try to compile against an arm64 version of Qt5 I also can't reproduce the issue. (note: @csuft that Qt5 isn't officially supported natively on M1 so your applications will have to rely on Rosetta2 x86_64 translation which will eventually be removed in the future). |
I am closing the issue for now. If there is new feedback on this - please feel free to share it and we could reopen it. |
I'm seeing this issue now, when trying to run a Universal (Intel+AppleSilicon) app built using Qt 6.3.2, running on an intel MacBook. When I run the app from the terminal I simply see:
Is the M1-2/arm support not likely to work? I was hoping to deploy singleapplication for our mac users ... |
I am going to need help with this as I don't have access to an M1 machine.
Would it be possible for you to investigate and submit a PR?
…On Thu, 27 Oct 2022, 16:13 danryu, ***@***.***> wrote:
I'm seeing this issue now, when trying to run a Universal
(Intel+AppleSilicon) app built using Qt 6.3.2 on an intel MacBook.
When I run the app from the terminal I simply see:
SingleApplication: Unable to create block.
SingleApplication: 1 "QSharedMemoryPrivate::initKey: unable to set key on lock"
Is the M1-2/arm support not likely to work? I was hoping to deploy
singleapplication for our mac users ...
(app here: https://github.com/koord-live/koord-app )
—
Reply to this email directly, view it on GitHub
<#136 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQGP534VAS5CENSLQ6KB6TWFJ5YBANCNFSM5BQCD4XQ>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
I also don't have access to an M1 machine. |
Is it necessary to actually have a physical M1 mac, if I can reproduce the error by running the Universal build on intel? Otherwise is this a Won't Fix scenario? |
I - apparently - have access to an M1, what would be required to reproduce this? (and to answer the question: M1 bugs are CPU-specific, the M1 macOS environment differs a lot from an intel* build and the intel slice of a universal binary is completely independent in it's behaviour) |
The universal build that fails for me on Intel will probably also fail for you on M1: If you install and run from Terminal, you will likely the same error I posted above.
I'm not sure this is an "M1 bug" or what one of those is exactly. I can say that the Universal build dmg installer is 39Mb in size, and the individual intel/M1 ones are 37Mb - only 2Mb smaller. |
@Shirk If that works/fails that would provide a good baseline for debugging :) |
You're looking at a DMG.. which is a compressed archive file and has zero indication of it's content sizes. If you remove the unused architecture part you can se that almost everything is different: /tmp % du -sh Koord.app
283M Koord.app
/tmp % du -sh Koord_thin_arm64.app
140M Koord_thin_arm64.app
/tmp % du -sh Koord_thin_intel.app
149M Koord_thin_intel.app The Problem is also not with QSingleApplication but rather with your codesigning entitlements which prevent shared memory usage, which in turn causes QSharedMemoryPrivate::initKey to fail. You can test this by "dummy signing" your application without a sandbox: Which produces a working application (because no sandboxing is enforced) |
Update - more research - still not QSingleApplication's fault; Qt has a number of "specialities" for Apple & the Mac AppStore:
|
Ahaa! This then is totally not what I expected. Maybe I should add a link
to that Qt article with specifics for MacOS.
…On Thu, 27 Oct 2022, 19:28 Renée Köcher, ***@***.***> wrote:
Update - more research - still not QSingleApplication's fault; Qt has a
number of "specialities" for Apple & the Mac AppStore:
- you need to build Qt6 yourself and make sure to use the
"-appstore-compliant" flag as per QTBUG-106910
<https://bugreports.qt.io/browse/QTBUG-106910>
- Shared memory has to be created in the form
"DEVTEAMID.app-group/shared"
- QSingleApplication could do that, but it would have to know about
the fact in the first place
- your app might require an associated app group on Apples profiles &
identifiers page (see Qt6 - QSharedMemory on Apple Platforms
<https://doc.qt.io/qt-6/qsharedmemory.html#details>)
[image: Screenshot 2022-10-27 at 18 23 ***@***.***
<https://user-images.githubusercontent.com/304352/198345918-8a1f8612-2cc6-4cc4-972b-1db1f1e9b0d3.png>
—
Reply to this email directly, view it on GitHub
<#136 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQGP52IPI5IBJJW7DDVPTDWFKUUBANCNFSM5BQCD4XQ>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
We can also change the name of the shared memory key automatically. I'll
read more into this. This may have been the missing link, but I have no way
to test any changes reliably.
…On Thu, 27 Oct 2022, 19:31 Itay Grudev, ***@***.***> wrote:
Ahaa! This then is totally not what I expected. Maybe I should add a link
to that Qt article with specifics for MacOS.
On Thu, 27 Oct 2022, 19:28 Renée Köcher, ***@***.***> wrote:
> Update - more research - still not QSingleApplication's fault; Qt has a
> number of "specialities" for Apple & the Mac AppStore:
>
> - you need to build Qt6 yourself and make sure to use the
> "-appstore-compliant" flag as per QTBUG-106910
> <https://bugreports.qt.io/browse/QTBUG-106910>
> - Shared memory has to be created in the form
> "DEVTEAMID.app-group/shared"
> - QSingleApplication could do that, but it would have to know
> about the fact in the first place
> - your app might require an associated app group on Apples profiles &
> identifiers page (see Qt6 - QSharedMemory on Apple Platforms
> <https://doc.qt.io/qt-6/qsharedmemory.html#details>)
>
> [image: Screenshot 2022-10-27 at 18 23 ***@***.***
> <https://user-images.githubusercontent.com/304352/198345918-8a1f8612-2cc6-4cc4-972b-1db1f1e9b0d3.png>
>
> —
> Reply to this email directly, view it on GitHub
> <#136 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAQGP52IPI5IBJJW7DDVPTDWFKUUBANCNFSM5BQCD4XQ>
> .
> You are receiving this because you modified the open/close state.Message
> ID: ***@***.***>
>
|
I don't need to do any of that normally. The Koord app has been building and running fine for ages, and also accepted without problem into App store. None of the links you specified are necessary. |
Well.. your binary is completely valid and thus can be code-signed and uploaded to the mac-appstore, but the shared memory QSingleApplication uses won't work because it does not follow the requirements for sandboxed applications. |
@itay-grudev |
The only thing I can do is to address the following points: Currently the shared memory uses the following as a key: SingleApplication/singleapplication_p.cpp Lines 131 to 185 in f1e1508
This code basically computes a hash based on the input data for single application (like application name, organisation, username, etc.) and computes a hash to be used as a shared memory identifier. I suppose we will have to use a different one that follows the scheme specified above. Just one question - is the |
I'm not 100% on this - but I think the (I think the Team-id is an alphanumeric token which Apple applies automatically in App Store Connect.) |
It doesn't - that's your App Groups always start with a "group." prefix You have to enable "App Groups" when creating the application identifier for you app and then select the group in order for the app to be allowed access: (also here)
Correct, you get assigned one Team-ID per account. It is randomly generated by Apple but does not change between applications. There's no way - I'm aware of - for QSingleApplication to determine these values other than the developer providing them at configuration time or via preprocessor defines. I hope this info helps. |
Many thanks @Shirk - this is indeed very helpful.
That I can do fairly easily I suppose. Not sure @itay-grudev how best this could/would be integrated with SingleApplication? (PS Apple certainly don't make it easy in this case do they? But I guess this support will only be more necessary in the future as Intel builds get phased out...) |
Yeah, they have most of it fully automated if you use XCode which even manages application IDs, group identifiers and signing entitlements for you but if you don't want to or can't use XCode it's a lot of documentation and forum knowledge to absorb and a lot of trial and error involved. (I only learned most of those things in the first place because it equally applies to iOS and has for years) |
Well, I've tried all the steps advised, but I still can't get it to work :(
Steps followed:
It's not yet clear to me from all the docs linked whether I have done everything right - in particular I'm not sure whether to use the "group." prefix on the Application Group id. It gets added automatically in Developer Center, but the Apple docs here suggest not to use it. I may be wrong though. Any help appreciated! |
You are correct, the docs state that the "group" prefix is only required on iOS, your |
Thanks @Shirk. I did re-create the iOS provisioning profile, but not yet for macOS. I will do this - but also need to remind myself how to apply the provisioning profile during the build with Qt. Not sure if I can use any options in |
Well, this has got me beaten. I can't get past the error on startup.
The best info I could find online regarding how to apply the provisioning profile on MacOS was here So I apply the file But the dmg installer (Koord_4.0.23.dmg) still results in a broken installation, with the app failing to start. I'm at a loss what to do now - I wanted to maintain the App Store presence of the app, but if I do this now I have to create build-time or run-time flags to avoid using SingleApplication when building for / running from an App Store build. |
Hmm, attempting to dump your embedded.provisionprofile gives me an ad-hoc profile, that might be the issue (I'm sorry I'm not more helpful): |
I call it "adhoc" to distinguish from the "store" certificates and profiles. |
Hang on, just checking this - which "codesigning entitlements" are causing The dmg installer is not signed with anything appstore-specific, nor is there any sandboxing involved as far as I know. The .app package is built and signed like so:
This does not involve the So now I'm really confused. I can't see why this error is still happening. |
OK - finally - I got past the error. I had this bit of cruft in my .entitlements file (which gets included in qmake project).
Which meant that the dmg installer was getting built with that constraint, despite it not being necessary. I now use a POSIXMAC define at compile stage to switch between no use of SingleApplication (for AppStore) and using SingleApplication (for dmg installer). This is annoying, as it means I now have differing feature sets between the two versions... At some point, somebody else out there will hopefully resolve this AppStore-compliance issue with SingleApplication/QSharedMemory! Until then all users installing from the App Store will get confusing multiple instances of our app. It feels like this shouldn't be such a rare use case!
And yet despite rebuilding Posix-compliant Qt from scratch, setting up app ids, app group ids, certificates and provisioning profiles, and patching Note: perhaps this should be logged in a separate issue, as this does not have anything to do with Apple M1 |
This is indeed a terrible experience, but I don't know I can do in this case. The only change SingleApplication can do is implement a function: But based on your experiments, that still wouldn't work. |
Thanks @itay-grudev, that itself would be a useful change, as it would save me forking SingleApplication or doing nasty build-time patches :) I guess this is a potential bug to log with Qt? I'm a little wary of doing that myself as it's on the boundaries of my Qt knowledge so I won't be that useful when interrogated by Qt devs in the issue thread! |
Just make sure you provide them with a minimal example reproducing the
problem.
And don't worry, they are pretty good at ignoring non-paying customers.
…On Sun, 6 Nov 2022, 10:24 Dan G, ***@***.***> wrote:
Thanks @itay-grudev <https://github.com/itay-grudev>, that itself would
be a useful change, as it would save me forking SingleApplication or doing
nasty build-time patches :)
I guess this is a potential bug to log with Qt? I'm a little wary of doing
that myself as it's on the boundaries of my Qt knowledge so I won't be that
useful when interrogated by Qt devs in the issue thread!
—
Reply to this email directly, view it on GitHub
<#136 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQGP55SOE5H4TEDFANX5YLWG5THRANCNFSM5BQCD4XQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Can confirm, I have a history with filing bugs with them - even actual broken core functionality in their less used modules and the average turn-around for a "not my problem" reply is 6-8 months. Provide that minimal example and a clear explanation of what you did, expected and what actually happened; link this issue if you want or at least the guides from Apple and then that's all you can really do honestly. Better to write it and leave a pesky reminder for Qt than have the knowledge go to waste. |
Creating a minimal example which demonstrates the issue out of the box is fairly tricky.
Do you think I have to detail all these steps as well - or can I assume a Qt Mac developer has XCode set up already to accommodate this stuff? |
Point them to their own documentation - they should know what they wrote themselves on POSIX / AppStore compliant builds. |
Thanks for the tips @Shirk @itay-grudev |
FYI @Shirk @itay-grudev
This is using Qt 6.4.1 configured and built for Universal (x86_64, arm64) with The only thing is that I have to patch |
Can you share your changes and I'll incorporate them. |
This is the patch I apply to SingleApplication: This is the according change I had to make to entitlements file: |
That should be doable with a CMake option or variable and turning singleapplication_p.cpp into a template you shove through Or just having the Shared-memory ID in an #if defined ( Q_OS_MACOS )
#ifndef MAS_TEAM_ID
# define MAS_TEAM_ID "single-app-default"
#endif
// need to overwrite for macOS - app store - POSIX shmem requirements
blockServerName = MSA_TEAM_ID "/shared";
#endif That way the user could easily set it at configure-time with a compiler define (-DMAS_TEAM_ID="12345abc.team"). |
It's my opinion that the The check will be only for MacOSX and I will need to add an extra method to SingleApplication akin to The final sharedMemoryName will be generated from the application name and team id. |
@itay-grudev This sounds great. I'm just wondering about this bit though:
The required format seems to be where As such, the app name and application group ID are not necessarily the same - although I made it the same in this case for simplicity and brevity (to stay under the char limit). |
We are aware of multiple issues with Qt's latest implementation of I'll close this issue for now as we no longer plan to work in the direction of |
Hi, it's nice to find this open source project and I added this project in our source code. It works like charm both on Windows and macOS, except for macOS with Apple M1. We received some feedbacks from our client that the application won't be launched after installation. The log looks like the following:
It seems the application is blocked because of lock in shared memory. I don't know if anybody encountered this issue before. There is a similar issue in list #58 but I am not sure how to resolve it.
The text was updated successfully, but these errors were encountered: