nextcloud / desktop

💻 Desktop sync client for Nextcloud
https://nextcloud.com/install/#install-clients
GNU General Public License v2.0
2.98k stars 784 forks source link

[Bug]: macOS Nextcloud Finder extension stops running, causing right-click menu to stop working #5193

Open briankendall opened 1 year ago

briankendall commented 1 year ago

⚠️ Before submitting, please verify the following: ⚠️

Bug description

This is a follow up to #4277 and #4459. I've opted to open a new issue as the previous issues were about a different crash that has since been fixed.

On a regular basis, sometimes multiple times per day, Nextcloud's Finder extension will stop running, causing the right-click menu to stop working. In order to get Finder integration working again, I need to restart Nextcloud.

I say "stop running" because macOS does not consider it to be crashing. There is no dialog box opening reporting a crashed process, and there is no crash log listed in ~/Library/Logs/DiagnosticReports. Nonetheless, if I check the list of running processes Nextcloud Extensions is not running. So it may be the case that the extension is erroneous "quitting normally" on its own, though it is possible that it is crashing and macOS is simply considering it a normal exit for some reason.

Steps to reproduce

Unfortunately I have found no consistent way to trigger this issue, but will update if I find one. However it will inevitably happen after Nextcloud has been running for several hours, though on occasion it has taken over a day to occur.

Expected behavior

Obviously the Finder extension should continue running.

Which files are affected by this bug

N/A

Operating system

Mac OS

Which version of the operating system you are running.

macOS 10.14.6

Package

Other

Nextcloud Server version

22.2.10

Nextcloud Desktop Client version

3.6.2git (build 12294)

Is this bug present after an update or on a fresh install?

Updated to a major version (ex. 3.3.6 to 3.4.0)

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

Are you using an external user-backend?

Nextcloud Server logs

N/A

Additional info

I'm a professional macOS and Qt developer, and would be happy to help debug this. I think the best initial approach to fixing this would be to attach a debugger to the Nextcloud Extensions and checking to see if a) it is actually crashing, or b) at least figure out what's triggering it to quit. However I don't offhandedly know how to do that since this project is a Qt project built using cmake. (I'm already familiar with using a debugger in Xcode and Qt Creator.) If someone could advise about how to do that, I'd be happy to do some debugging.

claucambra commented 1 year ago

Hi @briankendall I have been unable to reproduce these crashes personally, so any extra information from you would be super appreciated

There are a couple of ways you can gleam some logs for what is going on, as we have some logging in the finder extension:

briankendall commented 1 year ago

Here is the log from FinderSyncExt (and possibly a few other processes as well) shortly before it crashed. The first column is pid.

95771   default 13:59:48.208888 -0500   FinderSyncExt   27366555: RECEIVED OUT-OF-SEQUENCE NOTIFICATION: 100 vs 104, 640, <private>
97386   default 14:00:45.389431 -0500   FinderSyncExtension Current system appearance, (HLTB: 1), (SLS: 0)
97385   default 14:00:45.389910 -0500   FinderSyncExt   Current system appearance, (HLTB: 1), (SLS: 0)
97386   default 14:00:45.392751 -0500   FinderSyncExtension Post-registration system appearance: (HLTB: 1)
97385   default 14:00:45.392954 -0500   FinderSyncExt   Post-registration system appearance: (HLTB: 1)
97385   default 14:00:45.515379 -0500   FinderSyncExt   NSApp cache appearance:
-NSRequiresAquaSystemAppearance: 0
-appearance: (null)
-effectiveAppearance: <NSCompositeAppearance: 0x7f92b2f087c0
 (
    "<NSAquaAppearance: 0x7f92b2f079e0>",
    "<NSSystemAppearance: 0x7f92b2f08080>"
)>
97385   default 14:00:45.573603 -0500   FinderSyncExt   Socket path: /Users/user2/Library/Group Containers/com.nextcloud.desktopclient/.socket
97385   default 14:00:45.573700 -0500   FinderSyncExt   Init line processor with delegate.
97385   default 14:00:45.573748 -0500   FinderSyncExt   Initiating local socket client.
97385   default 14:00:45.573830 -0500   FinderSyncExt   Checking is connected: NO
97385   default 14:00:45.573895 -0500   FinderSyncExt   Opening local socket...
97385   default 14:00:45.573969 -0500   FinderSyncExt   Local socket opened. Connecting to '/Users/user2/Library/Group Containers/com.nextcloud.desktopclient/.socket' ...
97385   default 14:00:45.574117 -0500   FinderSyncExt   Connected to socket. Setting up dispatch sources...
97385   default 14:00:45.574178 -0500   FinderSyncExt   Starting to read from socket
97385   default 14:00:45.574235 -0500   FinderSyncExt   Checking is connected: YES
97385   default 14:00:45.574300 -0500   FinderSyncExt   Writing to out buffer: 'GET_STRINGS:
'
97385   default 14:00:45.574335 -0500   FinderSyncExt   Out buffer now 13 bytes
97385   default 14:00:45.574361 -0500   FinderSyncExt   Resuming write dispatch source.
97385   default 14:00:45.574436 -0500   FinderSyncExt   Checking is connected: YES
97385   default 14:00:45.574499 -0500   FinderSyncExt   About to write 13 bytes from outbuffer to socket.
97385   default 14:00:45.574598 -0500   FinderSyncExt   Wrote 13 bytes to socket. Line written was: 'GET_STRINGS:
'
97385   default 14:00:45.574659 -0500   FinderSyncExt   Out buffer cleared. Now count is 0 bytes.
97385   default 14:00:45.574699 -0500   FinderSyncExt   Out buffer has been emptied, suspending write dispatch source.
97385   default 14:00:45.575157 -0500   FinderSyncExt   Checking is connected: YES
97385   default 14:00:45.575209 -0500   FinderSyncExt   Reading from socket.
97385   default 14:00:45.575254 -0500   FinderSyncExt   Read 371 bytes from socket.
97385   default 14:00:45.575320 -0500   FinderSyncExt   Processing in buffer. In buffer length 371
97385   default 14:00:45.575405 -0500   FinderSyncExt   Processing line: REGISTER_PATH:/Users/user2/Sync/Apps/1Password
97385   default 14:00:45.575480 -0500   FinderSyncExt   Command: REGISTER_PATH
97385   default 14:00:45.575580 -0500   FinderSyncExt   Processing line: GET_STRINGS:BEGIN
97385   default 14:00:45.575625 -0500   FinderSyncExt   Command: GET_STRINGS
97385   default 14:00:45.575709 -0500   FinderSyncExt   Processing line: STRING:SHARE_MENU_TITLE:Share options
97385   default 14:00:45.575795 -0500   FinderSyncExt   Command: STRING
97385   default 14:00:45.575937 -0500   FinderSyncExt   Processing line: STRING:FILE_ACTIVITY_MENU_TITLE:Activity
97385   default 14:00:45.575978 -0500   FinderSyncExt   Command: STRING
97385   default 14:00:45.575978 -0500   FinderSyncExt   Registering path /Users/user2/Sync/Apps/1Password
97385   default 14:00:45.576082 -0500   FinderSyncExt   Processing line: STRING:CONTEXT_MENU_TITLE:Nextcloud
97385   default 14:00:45.576127 -0500   FinderSyncExt   Command: STRING
97385   default 14:00:45.576186 -0500   FinderSyncExt   Setting string SHARE_MENU_TITLE to value Share options
97385   default 14:00:45.576205 -0500   FinderSyncExt   Processing line: STRING:COPY_PRIVATE_LINK_MENU_TITLE:Copy private link to clipboard
97385   default 14:00:45.576248 -0500   FinderSyncExt   Setting string FILE_ACTIVITY_MENU_TITLE to value Activity
97385   default 14:00:45.576276 -0500   FinderSyncExt   Command: STRING
97385   default 14:00:45.576295 -0500   FinderSyncExt   Setting string CONTEXT_MENU_TITLE to value Nextcloud
97385   default 14:00:45.576351 -0500   FinderSyncExt   Processing line: STRING:EMAIL_PRIVATE_LINK_MENU_TITLE:Send private link by email …
97385   default 14:00:45.576365 -0500   FinderSyncExt   Setting string COPY_PRIVATE_LINK_MENU_TITLE to value Copy private link to clipboard
97385   default 14:00:45.576381 -0500   FinderSyncExt   Command: STRING
97385   default 14:00:45.576448 -0500   FinderSyncExt   Setting string EMAIL_PRIVATE_LINK_MENU_TITLE to value Send private link by email …
97385   default 14:00:45.576473 -0500   FinderSyncExt   Processing line: STRING:CONTEXT_MENU_ICON:Nextcloud-macOS
97385   default 14:00:45.576517 -0500   FinderSyncExt   Command: STRING
97385   default 14:00:45.576560 -0500   FinderSyncExt   Processing line: GET_STRINGS:END
97385   default 14:00:45.576561 -0500   FinderSyncExt   Setting string CONTEXT_MENU_ICON to value Nextcloud-macOS
97385   default 14:00:45.576613 -0500   FinderSyncExt   Command: GET_STRINGS
97385   default 14:00:45.576645 -0500   FinderSyncExt   No separator found. Stopping.
97385   default 14:00:45.576704 -0500   FinderSyncExt   Read -1 bytes from socket.
97385   default 14:00:45.576748 -0500   FinderSyncExt   No error and no data. Stopping.
97386   default 14:00:55.388914 -0500   FinderSyncExtension LSExceptions shared instance invalidated for timeout.
97385   default 14:00:55.388914 -0500   FinderSyncExt   LSExceptions shared instance invalidated for timeout.

There is no crash log in ~/Library/Logs/DiagonsticReports, but FinderSyncExt is no longer running and the Nextcloud Finder integration has once again stopped working.

briankendall commented 1 year ago

I've just checked the logs after a few more crashes, and I've concluded that nothing in particular is being printed when the crash occurs, since in a few cases there was nothing printed at all between the last line of output when the extension was working, and when it crashed.

claucambra commented 1 year ago

That's a shame. I've tried several times but I haven't been able to reproduce this issue at all. If there is not crash report in Console.app and nothing strange in the logging output for the finder sync extension I suspect the system is doing something weird here

briankendall commented 1 year ago

I'd like to see if I can attach a debugger to the Finder extension process. I'll probably have to build Nextcloud Desktop from source to do that. Not sure when I'll have a chance. But if you have any advice for how to do that, please do pass it on.

claucambra commented 1 year ago

Couple of notes:

github-actions[bot] commented 1 year ago

This issue has been marked as "needs info" 4 weeks ago. Please take a look again and try to provide the information requested, otherwise the issue will be automatically closed in 2 weeks. Thank you!

briankendall commented 1 year ago

I just upgraded the Nextcloud Desktop 3.7.1 and will check to see if the bug is still present there. I haven't yet had a chance to debug this though since life and work has kept me quite busy!

briankendall commented 1 year ago

The Finder sync extension is now crashing for me multiple times a day -- still no crash logs. It's rendering Nextcloud next to unusable. Often times I'll need to restart the app two or three times before I can actually get a right-click menu on any of my synced files!

I'm trying to figure out how I can use a debugger to get to the bottom of this crash. So far I've got Nextcloud Desktop successfully building on my system using cmake.

However I'm hitting a brick wall because this is a cmake project. I'm not aware of any workflow for using a debugger on a Finder sync extension from a cmake project, and as near as I can tell, no one on the internet has ever published a method for doing so.

I tried using cmake -G Xcode ... to generate an Xcode project, but since it's a non-standard cmake-generated Xcode project, there is no app extension target in it that I can use to debug. It does produce a seperate Xcode project for building the extension, but since it's not actually part of the main Xcode project generated by cmake, I'm not able to debug anything with it. Worse still, even if I just try to run Nextcloud from within the generated Xcode project, it immediately crashes, probably because there's some important build or release step that's not being executed that would normally when just using cmake on its own.

I need help! Does anyone have any idea how to debug the extension?

edit: Also, I can't get the Finder extension to launch from any copy of Nextcloud I build myself, using cmake on its own or cmake + Xcode. I made sure the app bundle it produced is signed with my developer ID, both with my own codesign command that includes Nextcloud's entitlements, or using admin/osx/sign_app.sh that preserves entitlements, but that doesn't help.

claucambra commented 1 year ago

You should in theory be able to just open the Xcode project file for the Finder Sync extension in Xcode, run the FinderSyncExt scheme, and attach a debugger to the process. I've often found this to be super finicky/unreliable but YMMV.

However, the extension not being invoked at all is not something that has ever happened to me. Are you:

  1. Building with -DBUILD_OWNCLOUD_OSX_BUNDLE=ON ?
  2. Does the codesigning complete successfully? (It can sometimes fail in sneaky ways) Are you signing with deep and with preserve-entitlements? I don't personally use the sign_app.sh so I can't vouch for it
  3. Most importantly -- do you have any other active finder sync extensions running? Is the Nextcloud extension active in your system settings?

Not that this helps, but yours is the first report I have heard of the FinderSyncExt crashing/stopping/quitting like this, which makes me think that there is something weird going on with your Finder, and this is giving me flashbacks of clashes when multiple Finder Sync Extensions are active...

briankendall commented 1 year ago

Yes, I am building with -DBUILD_OWNCLOUD_OSX_BUNDLE=ON. After some more digging, I found that the normal method of building Nextcloud does not produce the Finder sync extension with any executable in it! I have no idea why. But I have managed to get the Finder extension running using the following method:

  1. Take an official build of Nextcloud
  2. Remove its Finder sync extension
  3. Copy in the Finder sync extension I built myself using the OwnCloudFinderSync Xcode project
  4. Resign Nextcloud.app using both --deep and preserve-entitlements and my own developer ID

Now when I launch Nextcloud, the extension will launch too, and since it's the debug build I made it actually has debug info embedded in it that I can make use of. However, I still cannot get Xcode to actually attach a debugger to it, no matter how closely I follow the steps for debugging a Finder extension.

I've resorted to just using the command line lldb to try and debug this. I've got it attached and I'm waiting for the extension to crash. Hopefully at that point I'll be able to get anything useful out of it! I've barely used lldb on its own so far.

briankendall commented 1 year ago

Quick update: I'm not sure exactly how I did it, but I'm finally able to get Xcode to debug the Finder extension process. I'll see if I can finally get to the bottom of what's causing it to crash on my system.

briankendall commented 1 year ago

Okay, after several days of continuous debugging, what I've observed is:

  1. For some reason, my own build of this is working a lot better than the official build I had installed at /Applications/Nextcloud.app
  2. The extension is terminating, but it's terminating normally. This seems to happen roughly once a day.
  3. A new extension process is automatically started when it terminates

As near as I can tell, the cause of the issue I reported is that, for some reason, the Finder extension was frequently being terminated normally and then not restarted. I don't know why it's affected both of my systems but not anyone else. It does seem to be a macOS issue, though, and not a Nextcloud issue, as the extension itself is not crashing. And even more confusingly, compiling it myself seems to solve the issue. Maybe there's something about the way the Finder has registered this new build of the extension that's fortuitously rejiggered things into a working state.

In any case, I guess I'm suggesting that this issue be closed. However I'm going to keep futzing with it in the hopes that I can massage things into a permanently working state, and if I learn anything new, I could report it back here.

claucambra commented 1 year ago

Hi @briankendall thanks for following up and trying to figure out what is going on here. It's a weird bug for sure, but I'm happy that at least your own build of the client is working properly :)

As you suggested I will close this issues, but please do update the issue if you find anything new -- I'm pretty interested to see if we are actually doing something wrong here

pjrobertson commented 2 months ago

I am still experiencing a similar issue here. The way I am able to (temporarily) solve this is to restart finder using killall finder in terminal.

s-a-s-k-i-a commented 3 weeks ago

Hello!

I am seeing the very same issue on my Macbook Pro with Apple M3 Max running Mac OS 14.6.1 with stable Nextcloud Desktop-Client 3.13.2

I have no idea tbh, what is causing this issue and it drives me nuts. Its not happening very often, but it does happen once in a while and when it does, I start googling and do a lot of time wasting things trying to debug this. Please releave me from this and fix your app!

Thanks Saskia