documentserver_community icon indicating copy to clipboard operation
documentserver_community copied to clipboard

cron-Job of nextcloud server fails with TypeError : stream_get_contents() expects parameter 1 to be resource, bool given in /var/www/html/nextcloud/apps/documentserver_community/lib/Document/DocumentStore.php:173

Open kinimoas opened this issue 4 years ago • 9 comments

I get the following error on the cron-job twice a day

TypeError: stream_get_contents() expects parameter 1 to be resource, bool given in /var/www/html/nextcloud/apps/documentserver_community/lib/Document/DocumentStore.php:173
Stack trace:
#0 /var/www/html/nextcloud/apps/documentserver_community/lib/Document/DocumentStore.php(173): stream_get_contents()
#1 /var/www/html/nextcloud/apps/documentserver_community/lib/LocalAppData.php(102): OCA\DocumentServer\Document\DocumentStore->OCA\DocumentServer\Document\{closure}()
#2 /var/www/html/nextcloud/apps/documentserver_community/lib/Document/DocumentStore.php(176): OCA\DocumentServer\LocalAppData->getReadWriteLocalPath()
#3 /var/www/html/nextcloud/apps/documentserver_community/lib/Document/SaveHandler.php(58): OCA\DocumentServer\Document\DocumentStore->saveChanges()
#4 /var/www/html/nextcloud/apps/documentserver_community/lib/BackgroundJob/Cleanup.php(71): OCA\DocumentServer\Document\SaveHandler->flushChanges()
#5 /var/www/html/nextcloud/lib/public/BackgroundJob/Job.php(79): OCA\DocumentServer\BackgroundJob\Cleanup->run()
#6 /var/www/html/nextcloud/cron.php(128): OCP\BackgroundJob\Job->execute()
#7 {main}

Nextcloud version Nextcloud Hub II (23.0.0)

Community Document Server 0.1.11

I'm aware that this version fo teh document server is not recomented for the newest version of nextcloud server. Maybe this is useful anyway.

kinimoas avatar Dec 03 '21 15:12 kinimoas

This only occurs twice a day

kinimoas avatar Dec 03 '21 15:12 kinimoas

Same here. Though it started (possibly after some more recent updates) about 12 days ago with this:

Error: Call to a member function getId() on bool in /path-to-public_html/apps/files_versions/lib/Storage.php:197
Stack trace:
#0 /path-to-public_html/apps/files_versions/lib/Hooks.php(56): OCA\Files_Versions\Storage::store()
#1 /path-to-public_html/lib/private/legacy/OC_Hook.php(106): OCA\Files_Versions\Hooks::write_hook()
#2 /path-to-public_html/lib/private/Files/View.php(1284): OC_Hook::emit()
#3 /path-to-public_html/lib/private/Files/View.php(1154): OC\Files\View->runHooks()
#4 /path-to-public_html/lib/private/Files/View.php(706): OC\Files\View->basicOperation()
#5 /path-to-public_html/lib/private/Files/Node/File.php(71): OC\Files\View->file_put_contents()
#6 /path-to-public_html/apps/documentserver_community/lib/Document/DocumentStore.php(173): OC\Files\Node\File->putContent()
#7 /path-to-public_html/apps/documentserver_community/lib/LocalAppData.php(102): OCA\DocumentServer\Document\DocumentStore->OCA\DocumentServer\Document\{closure}()
#8 /path-to-public_html/apps/documentserver_community/lib/Document/DocumentStore.php(176): OCA\DocumentServer\LocalAppData->getReadWriteLocalPath()
#9 /path-to-public_html/apps/documentserver_community/lib/Document/SaveHandler.php(58): OCA\DocumentServer\Document\DocumentStore->saveChanges()
#10 /path-to-public_html/apps/documentserver_community/lib/BackgroundJob/Cleanup.php(71): OCA\DocumentServer\Document\SaveHandler->flushChanges()
#11 /path-to-public_html/lib/public/BackgroundJob/Job.php(79): OCA\DocumentServer\BackgroundJob\Cleanup->run()
#12 /path-to-public_html/cron.php(150): OCP\BackgroundJob\Job->execute()
#13 {main}

And since 2 days, I get the same error as OP. Also twice per day.

Versions: Nextcloud Hub II (23.0.4) Community Document Server (0.1.12) System: Ubuntu 18.04 LTS, PHP 8.0.19 (not in Docker)

ElpyDE avatar May 24 '22 15:05 ElpyDE

same proble here

igherardia avatar May 27 '22 17:05 igherardia

I am getting the same error when running occ documentserver:flush.

Stacktrace:

An unhandled exception has been thrown:
TypeError: stream_get_contents() expects parameter 1 to be resource, bool given in /var/www/html/nextcloud/apps/documentserver_community/lib/Document/DocumentStore.php:173
Stack trace:
#0 /var/www/html/nextcloud/apps/documentserver_community/lib/Document/DocumentStore.php(173): stream_get_contents()
#1 /var/www/html/nextcloud/apps/documentserver_community/lib/LocalAppData.php(102): OCA\DocumentServer\Document\DocumentStore->OCA\DocumentServer\Document\{closure}()
#2 /var/www/html/nextcloud/apps/documentserver_community/lib/Document/DocumentStore.php(176): OCA\DocumentServer\LocalAppData->getReadWriteLocalPath()
#3 /var/www/html/nextcloud/apps/documentserver_community/lib/Document/SaveHandler.php(58): OCA\DocumentServer\Document\DocumentStore->saveChanges()
#4 /var/www/html/nextcloud/apps/documentserver_community/lib/Command/FlushChanges.php(74): OCA\DocumentServer\Document\SaveHandler->flushChanges()
#5 /var/www/html/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\DocumentServer\Command\FlushChanges->execute()
#6 /var/www/html/nextcloud/core/Command/Base.php(168): Symfony\Component\Console\Command\Command->run()
#7 /var/www/html/nextcloud/3rdparty/symfony/console/Application.php(1009): OC\Core\Command\Base->run()
#8 /var/www/html/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#9 /var/www/html/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#10 /var/www/html/nextcloud/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run()
#11 /var/www/html/nextcloud/console.php(100): OC\Console\Application->run()
#12 /var/www/html/nextcloud/occ(11): require_once('/var/www/html/n...')
#13 {main}

This is really critical, as apparently that is the only method to avoid data loss according to #12 and #281 - as of now, none of our collaboratively edited files get synced to disk at all, they are all outdated by weeks! And due to this, I cannot even sync them manually or with a cronjob. :(

adsche avatar Feb 07 '23 20:02 adsche

Digging into the source:

The method is called in DocumentStore.php, l. 173, with a variable $savedContent as parameter. $savedContent is initialized in l. 158 of the same file with `fopen(...). According to php docs, fopen "[r]eturns a file pointer resource on success, or false on failure".

So, apparently, opening a file fails but there is no error handling of the fopen call, even though filesystem calls fail relatively often. :( The error-return value false is just passed along and used instead of a stream.

adsche avatar Feb 07 '23 20:02 adsche

In our case, the specific error was triggered because a file had been renamed by someone* while open for someone else, and the file extension changed (docx -> bak). However, the above mentioned code just assumes an extension and appends it to the file name without error checking. Not sure if changing the extension was relevant or if any renaming makes this fail.

*) because of https://github.com/nextcloud/documentserver_community/issues/12 and https://github.com/nextcloud/documentserver_community/issues/281

adsche avatar Feb 22 '23 19:02 adsche

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 60 days. Thank you for your contribution!

Retaking repo management include inheritance of old, not treated, and probablty obsolete issues, this is why it was decided to mark issues as stale.

github-actions[bot] avatar Sep 30 '24 00:09 github-actions[bot]

There's still no error handling on the fopen() call, so this bug is still easily triggered by renaming files.

https://github.com/nextcloud/documentserver_community/blob/d3fbf99169857f9d8fb77bf95e29ad7339342c25/lib/Document/DocumentStore.php#L158-L173

adsche avatar Sep 30 '24 06:09 adsche