nextcloud / desktop

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

The process cannot access the file because it is being used by another process #4502

Open rajendradewani opened 2 years ago

rajendradewani commented 2 years ago

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

Bug description

I am using Windows 10, NextCloud 3.5.0

NextCloud will not upload files being used by uTorrent/BitTorrent - Completed folder. “The process cannot access the file because it is being used by another process.”

Nextcloud will remove the files on failed to upload.

Steps to reproduce

NextCloud client is using virtual file links.

I have set up uTorrent/BitTorrent to download files.

New files get downloaded to c:\Pending\Tutorial on complete, the files will be moved to c:\Nextcloud_DONE/downloads\

Nextcloud will notice new files added and will attempt to upload but it will throw the following message

“The process cannot access the file because it is being used by another process.” uTorrent / BitTorrent app has copied in the file after download but is still reading it to share with other users.

Logs. 2022-05-06 08:57:06:777 [ debug nextcloud.sync.database.sql C:\Users\sysadmin\AppData\Local\Temp\2\windows-10062\client-building\desktop\src\common\ownsql.cpp:295 ] [ OCC::SqlQuery::exec ]: SQL exec “SELECT path, inode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, contentchecksumtype.name || ‘:’ || contentChecksum, e2eMangledName, isE2eEncrypted, lock, lockOwnerDisplayName, lockOwnerId, lockType, lockOwnerEditor, lockTime, lockTimeout FROM metadata LEFT JOIN checksumtype as contentchecksumtype ON metadata.contentChecksumTypeId == contentchecksumtype.id WHERE phash=?1” 2022-05-06 08:57:06:778 [ debug nextcloud.sync.database.sql C:\Users\sysadmin\AppData\Local\Temp\2\windows-10062\client-building\desktop\src\common/ownsql.h:145 ] [ OCC::SqlQuery::bindValue ]: SQL bind 1 8052429941439445994 2022-05-06 08:57:06:778 [ debug nextcloud.sync.database.sql C:\Users\sysadmin\AppData\Local\Temp\2\windows-10062\client-building\desktop\src\common\ownsql.cpp:295 ] [ OCC::SqlQuery::exec ]: SQL exec “SELECT path, inode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, contentchecksumtype.name || ‘:’ || contentChecksum, e2eMangledName, isE2eEncrypted, lock, lockOwnerDisplayName, lockOwnerId, lockType, lockOwnerEditor, lockTime, lockTimeout FROM metadata LEFT JOIN checksumtype as contentchecksumtype ON metadata.contentChecksumTypeId == contentchecksumtype.id WHERE phash=?1” 2022-05-06 08:57:06:778 [ warning nextcloud.gui.activity C:\Users\sysadmin\AppData\Local\Temp\2\windows-10062\client-building\desktop\src\gui\tray\usermodel.cpp:631 ]: Item “_DONE/downloads/Tutorial001/Tutorial-Sample-Video.mkv” retrieved resulted in “The process cannot access the file because it is being used by another process.” 2022-05-06 08:57:06:778 [ warning nextcloud.gui.activity C:\Users\sysadmin\AppData\Local\Temp\2\windows-10062\client-building\desktop\src\gui\tray\usermodel.cpp:607 ]: Item “_DONE/downloads/Tutorial001/Tutorial-Sample-Video.mkv” retrieved resulted in error “The process cannot access the file because it is being used by another process.” 2022-05-06 08:57:06:778 [ info nextcloud.gui.activity C:\Users\sysadmin\AppData\Local\Temp\2\windows-10062\client-building\desktop\src\gui\tray\activitylistmodel.cpp:546 ]: Error successfully added to the notification list: “The process cannot access the file because it is being used by another process.” 2022-05-06 08:57:06:783 [ debug nextcloud.sync.database.sql C:\Users\sysadmin\AppData\Local\Temp\2\windows-10062\client-building\desktop\src\common/ownsql.h:145 ] [ OCC::SqlQuery::bindValue ]: SQL bind 1 -8787998027952910409

Expected behavior

NextCloud should be able to upload it and should not throw any errors. NextCloud sync app should be able to read a file that is being read by another app. ... Files should get uploaded no matter if it is being read by any application including (Bittorrent/uTorrent). NextCloud should not remove the file if any other process is using it.

Which files are affected by this bug

mkv

Operating system

Windows

Which version of the operating system you are running.

Windows 10

Package

Distro package manager

Nextcloud Server version

24.0.0 on Linux 5.13.0-40-generic x86_64

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

Fresh desktop client install

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

Are you using an external user-backend?

Nextcloud Server logs

No response

Additional info

No response

joshtrichards commented 10 months ago

Hi @rajendradewani - This is not a bug in the Nextcloud client. It's possible to create a lock that prevents any sharing (i.e. opening of the file) by another process - even just for reading. It sounds like the other application is doing that.

Taudris commented 10 months ago

The client should wait until the lock is released before syncing the file. It should not produce "could not be synced due to an error" notifications for this case, either (or at least, notifications with this specific cause should be able to be toggled off).

joshtrichards commented 10 months ago

NextCloud should not remove the file if any other process is using it.

@rajendradewani Apologies as I just re-read and noticed the above part, which would be unexpected behavior.

Can you clarify what you mean by the file is being removed? From your local filesystem? From the server? Can you provide some evidence that the client is deleting it? That does sound wrong.

Taudris commented 10 months ago

I'm not the original poster, and I'm not having the exact same issue they're having with files being deleted, but I did find the same error message in the log ("The process cannot access the file because it is being used by another process."), so I figured OP's issue and mine could have a similar root cause.

My issue is that I get spammed with Windows notifications from the Nextcloud desktop client saying "could not be synced due to an error" in a couple of use cases:

  1. Creating a backup of my Lightroom catalog in my Nextcloud folder (I forget what happens if I put the catalog itself on Nextcloud directly)
  2. Using Visual Studio 2022 to open a C# project/solution stored in my Nextcloud folder - a notification pops up something like a few times a minute as I'm making code changes

I also just found a really easy-to-reproduce behavior using Notepad++ v8.6. Save a file into the Nextcloud folder, switch away for a couple seconds or so, then switch back. If you switched slowly enough, you'll get a popup saying "This file has been modified by another program, would you like to reload it?" When you reload it, there are no observable changes. This should absolutely not be happening.

I'm using Windows 11 23H2 build 22631.2715 with Nextcloud desktop client version 3.10.1. The Lightroom problems have persisted through numerous client versions. I only recently discovered the VS and N++ problems.