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

Cannot modify header information (Sapi.php:132) NC 19.0.2 #22509

Closed
altosch opened this issue Aug 31, 2020 · 106 comments
Closed

Cannot modify header information (Sapi.php:132) NC 19.0.2 #22509

altosch opened this issue Aug 31, 2020 · 106 comments
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap bug needs info

Comments

@altosch
Copy link

altosch commented Aug 31, 2020

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Steps to reproduce

Upgrade to NC 19.0.2.

Expected behaviour

No PHP errors in the log.

Actual behaviour

Since upgrade to 19.0.2 many error messages like this in the log:

[PHP] Error: Cannot modify header information - headers already sent by 
(output started at /var/www/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132) 
at /var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php#680

PUT /remote.php/dav/uploads/john/4291849725/00000002
from 111.222.333.444 by john at 2020-08-29T19:34:41+02:00
{"reqId":"Or0R2pucFGt5YGzIyZcI","level":3,"time":"2020-08-29T19:34:41+02:00","remoteAddr":"111.222.333.444",
"user":"john","app":"PHP","method":"PUT","url":"/remote.php/dav/uploads/john/4291849725/00000002",
"message":"Cannot modify header information - headers already sent by 
(output started at /var/www/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132)
 at /var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php#680",
"userAgent":"Mozilla/5.0 (Windows) mirall/2.6.5stable-Win64 (build 20200710) (Nextcloud)","version":"19.0.2.2","id":"5f4c9578c0b93"}

Server configuration

Operating system:
Ubuntu 18.04.5 LTS
Web server:
nginx version: nginx/1.19.2
Database:
MariaDB 10.1.44
PHP version:
7.2.33 (PHP 7.2.33-1+ubuntu18.04.1+deb.sury.org+1)
Nextcloud version:
19.0.2
Updated from an older Nextcloud/ownCloud or fresh install:
Updated from 18.0.8
Where did you install Nextcloud from:
Web admin update
Signing status:

Signing status
No errors have been found.

List of activated apps:

App list
Enabled:
  - accessibility: 1.5.0
  - activity: 2.12.0
  - admin_audit: 1.9.0
  - calendar: 2.0.4
  - cloud_federation_api: 1.2.0
  - comments: 1.9.0
  - contacts: 3.3.0
  - contactsinteraction: 1.0.0
  - dav: 1.15.0
  - federatedfilesharing: 1.9.0
  - files: 1.14.0
  - files_pdfviewer: 1.8.0
  - files_rightclick: 0.16.0
  - files_sharing: 1.11.0
  - files_trashbin: 1.9.0
  - files_versions: 1.12.0
  - files_videoplayer: 1.8.0
  - logreader: 2.4.0
  - lookup_server_connector: 1.7.0
  - nextcloud_announcements: 1.8.0
  - notes: 3.6.4
  - notifications: 2.7.0
  - oauth2: 1.7.0
  - password_policy: 1.9.1
  - photos: 1.1.0
  - privacy: 1.3.0
  - provisioning_api: 1.9.0
  - recommendations: 0.7.0
  - richdocuments: 3.7.3
  - serverinfo: 1.9.0
  - settings: 1.1.0
  - sharebymail: 1.9.0
  - spreed: 9.0.3
  - support: 1.2.1
  - tasks: 0.13.3
  - text: 3.0.1
  - theming: 1.10.0
  - twofactor_backupcodes: 1.8.0
  - updatenotification: 1.9.0
  - viewer: 1.3.0
  - workflowengine: 2.1.0
Disabled:
  - encryption
  - federation
  - files_external
  - firstrunwizard
  - survey_client
  - systemtags
  - user_ldap

Nextcloud configuration:

Config report
{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "localhost",
            "cloud.mydomain.com"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "overwrite.cli.url": "https:\/\/cloud.mydomain.com",
        "dbtype": "mysql",
        "version": "19.0.2.2",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "activity_expire_days": 14,
        "auth.bruteforce.protection.enabled": true,
        "blacklisted_files": [
            ".htaccess",
            "Thumbs.db",
            "thumbs.db"
        ],
        "cron_log": true,
        "enable_previews": true,
        "enabledPreviewProviders": [
            "OC\\Preview\\PNG",
            "OC\\Preview\\JPEG",
            "OC\\Preview\\GIF",
            "OC\\Preview\\BMP",
            "OC\\Preview\\XBitmap",
            "OC\\Preview\\Movie",
            "OC\\Preview\\PDF",
            "OC\\Preview\\MP3",
            "OC\\Preview\\TXT",
            "OC\\Preview\\MarkDown"
        ],
        "filesystem_check_changes": 0,
        "filelocking.enabled": "true",
        "htaccess.RewriteBase": "\/",
        "integrity.check.disabled": false,
        "knowledgebaseenabled": false,
        "logfile": "\/var\/nc_data\/nextcloud.log",
        "loglevel": 2,
        "logtimezone": "Europe\/Prague",
        "log_rotate_size": 104857600,
        "maintenance": false,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "overwriteprotocol": "https",
        "preview_max_x": 1024,
        "preview_max_y": 768,
        "preview_max_scale_factor": 1,
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "timeout": 0
        },
        "quota_include_external_storage": false,
        "share_folder": "\/Shares",
        "skeletondirectory": "",
        "theme": "",
        "trashbin_retention_obligation": "auto, 7",
        "updater.release.channel": "stable",
        "mail_smtpmode": "smtp",
        "mail_smtpauthtype": "LOGIN",
        "mail_smtpsecure": "tls",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauth": 1,
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "587",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "mail_smtptimeout": 45,
        "force_language": "cs",
        "lost_password_link": "disabled",
        "mail_sendmailmode": "smtp"
    }
}

Are you using external storage, if yes which one: no

Are you using encryption: no

Are you using an external user-backend, if yes which one: no

Client configuration

Browser:

Operating system:

Logs

Web server error log

Web server error log
Insert your webserver log here

Nextcloud log (data/nextcloud.log)

Nextcloud log Similar messages repeated many times:
{"reqId":"xTDKPVJiXelxcS5xfQ2F","level":3,"time":"2020-08-28T16:03:27+02:00","remoteAddr":"555.666.777.888","user":"john","app":"no app in context","method":"PUT","url":"/remote.php/webdav/WORK/myfile.txt","message":{"Exception":"Sabre\\DAV\\Exception\\BadRequest","Message":"Expected filesize of 1303 bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) 0 bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side.","Code":0,"Trace":[{"file":"/var/www/nextcloud/apps/dav/lib/Connector/Sabre/Directory.php","line":154,"function":"put","class":"OCA\\DAV\\Connector\\Sabre\\File","type":"->","args":[null]},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":1104,"function":"createFile","class":"OCA\\DAV\\Connector\\Sabre\\Directory","type":"->","args":["myfile.txt",null]},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":527,"function":"createFile","class":"Sabre\\DAV\\Server","type":"->","args":["WORK/myfile.txt",null,null]},{"file":"/var/www/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpPut","class":"Sabre\\DAV\\CorePlugin","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":474,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["method:PUT",[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]]},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":251,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->","args":[{"__class__":"Sabre\\HTTP\\Request"},{"__class__":"Sabre\\HTTP\\Response"}]},{"file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php","line":319,"function":"start","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/nextcloud/apps/dav/appinfo/v1/webdav.php","line":82,"function":"exec","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/nextcloud/remote.php","line":167,"args":["/var/www/nextcloud/apps/dav/appinfo/v1/webdav.php"],"function":"require_once"}],"File":"/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php","Line":238,"CustomMessage":"--"},"userAgent":"--","version":"19.0.2.2"}

{"reqId":"Or0R2pucFGt5YGzIyZcI","level":3,"time":"2020-08-29T19:34:41+02:00","remoteAddr":"111.222.333.444","user":"john","app":"PHP","method":"PUT","url":"/remote.php/dav/uploads/john/4291849725/00000002","message":"Cannot modify header information - headers already sent by (output started at /var/www/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132) at /var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php#680","userAgent":"Mozilla/5.0 (Windows) mirall/2.6.5stable-Win64 (build 20200710) (Nextcloud)","version":"19.0.2.2"}

Browser log

Browser log
Insert your browser log here, this could for example include:

a) The javascript console log
b) The network log
c) ...
@altosch

This comment has been minimized.

@Shuvi-Hub

This comment has been minimized.

@AndyXheli

This comment has been minimized.

@Shuvi-Hub

This comment has been minimized.

@yewkay

This comment has been minimized.

@altosch
Copy link
Author

altosch commented Sep 11, 2020

It's back again after upgrade to 19.0.3. The number after hash in the log message has changed from 680 to 683.

Cannot modify header information - headers already sent by (output started at /var/www/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132) at /var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php#683

@csgt01

This comment has been minimized.

@papezg

This comment has been minimized.

@xmzl

This comment has been minimized.

@papezg
Copy link

papezg commented Sep 22, 2020

By reverting client to 2.6.5 the sync works again. Avoid client 3.x for now.

@boyi01
Copy link

boyi01 commented Oct 2, 2020

Same error in 19.0.3, even uploading via browser is not working...

I did little research, i can upload really smal files some kb, but imgaes some mb are not possible....

@PieterGit
Copy link

PieterGit commented Oct 7, 2020

Same error in Nextcloud 19.0.3. Uploading small text file in browser to WedDav external store is not working.
Frontend says: "Er trad een onbekende fout op." (dutch).
nextcloud.log says "Cannot modify header information - headers already sent by (output started at /nextcloud/3rdparty/sabre/http/lib/Sapi.php:132) at /apps/dav/lib/Connector/Sabre/File.php#683
Uploading same file to non-external storage and DropboxV2 storage works fine.
Uploading in the ios app to the WebDav external storage did also not work (500 error).

I found workaround that worked for me for the webclient. I removed my DropboxV2 external storage and removed the external dir of the WebDav storage. Now it works (both in the ios app and in the webclient).

@xmzl
Copy link

xmzl commented Oct 8, 2020

With Nextcloud 19.0.4 the situation does not change. Only one line number is different in the error message (#683 -> #690)
Error: Cannot modify header information - headers already sent by (output started at /var/www/html/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132) at /var/www/html/nextcloud/apps/dav/lib/Connector/Sabre/File.php#690

@Infratek34

This comment has been minimized.

@j0yze
Copy link

j0yze commented Oct 8, 2020

Same here. I did a fresh Nextcloud 20.0.0 installation and I get the following, if I upload a file to a shared folder through a shared link:

`Error: Cannot modify header information - headers already sent by (output started at /config/www/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132) at /config/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php#691
<<closure>>

OC\Log\ErrorHandler::onError(2, "Cannot modi ... )", "/config/www ... p", 691, { string: "X ... "})

/config/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php - line 691:

header("X-Hash-MD5: ... 9")

/config/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php - line 189:

OCA\DAV\Connector\Sabre\File->header("X-Hash-MD5: ... 9")

<<closure>>

OCA\DAV\Connector\Sabre\File->OCA\DAV\Connector\Sabre\{closure}("*** sensiti ... *")

/config/www/nextcloud/lib/private/Files/Stream/HashWrapper.php - line 71:

call_user_func(Closure {}, "*** sensiti ... *")

<<closure>>

OC\Files\Stream\HashWrapper->stream_close()

/config/www/nextcloud/3rdparty/icewind/streams/src/Wrapper.php - line 132:

fclose(null)

/config/www/nextcloud/lib/private/Files/Stream/HashWrapper.php - line 75:

Icewind\Streams\Wrapper->stream_close()

<<closure>>

OC\Files\Stream\HashWrapper->stream_close()

/config/www/nextcloud/3rdparty/icewind/streams/src/Wrapper.php - line 132:

fclose(null)

/config/www/nextcloud/lib/private/Files/Stream/HashWrapper.php - line 75:

Icewind\Streams\Wrapper->stream_close()

/config/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 319:

OC\Files\Stream\HashWrapper->stream_close()

/config/www/nextcloud/apps/dav/appinfo/v1/publicwebdav.php - line 113:

Sabre\DAV\Server->exec()

/config/www/nextcloud/public.php - line 81:

require_once("/config/www ... p")`

But I can upload without issues, if I login with my user account.

@Antimoon51
Copy link

Antimoon51 commented Oct 10, 2020

It's not a solution, but it is something.. I had the same error since I made an update to 19.0.3. But now the error is gone, after I changed the local network. I don't know how this affects anything, all I know is, that the working network has a better upstream (downstream is equal). I couldn't check yet if it still fails with this error in the other network, but maybe I can test later and will report interesting results.

@xmzl
Copy link

xmzl commented Oct 10, 2020

It's not a solution, but it is something.. I had the same error since I made an update to 19.0.3. But now the error is gone, after I changed the local network. I don't know how this affects anything, all I know is, that the working network has a better upstream (downstream is equal). I couldn't check yet if it still fails with this error in the other network, but maybe I can test later and will report interesting results.

I'm still trying to find solutions. Everything worked well with the 18.0.x then, from 19.0.3 onwards I can only upload files of less than 1.5 MB. This is as much with the Android/iOS client as it is with the browser. What puzzles me is that I can easily load 1 GB files if I use oClud.de

@prismopensource
Copy link

Same problem with 19.0.4 here, using client version 3.0.2 on Windows. No problems at all when uploading files through the web interface.

@sercasbh
Copy link

I had the same issue (NC 19.0.4)
I had configure an external storage to a SMB share that was off-line.
I remove the configuration and all works well

@simonspa
Copy link
Contributor

Here is a full stack trace, maybe that helps in understanding the underlying issue. In this case it was triggered by an upload from the Android app:

{
    "reqId": "vMp9gJTkQ9DTydtEtHBm",
    "level": 3,
    "time": "2020-10-16T23:20:17+02:00",
    "remoteAddr": "111.222.333.444",
    "user": "theuser",
    "app": "PHP",
    "method": "PUT",
    "url": "/remote.php/dav/uploads/theuser/35596bf55d30b13fda6d265b8f116e16/0000000000000000-0000000002351377",
    "message": {
        "Exception": "Error",
        "Message": "Cannot modify header information - headers already sent by (output started at /var/www/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132) at /var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php#690",
        "Code": 0,
        "Trace": [{
            "function": "onError",
            "class": "OC\\Log\\ErrorHandler",
            "type": "::",
            "args": [2, "Cannot modify header information - headers already sent by (output started at /var/www/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132)", "/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php", 690, {
                "string": "X-Hash-MD5: 4cb41cb7e045d80a78da4789ee637ede"
            }]
        }, {
            "file": "/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php",
            "line": 690,
            "function": "header",
            "args": ["X-Hash-MD5: 4cb41cb7e045d80a78da4789ee637ede"]
        }, {
            "file": "/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php",
            "line": 188,
            "function": "header",
            "class": "OCA\\DAV\\Connector\\Sabre\\File",
            "type": "->",
            "args": ["X-Hash-MD5: 4cb41cb7e045d80a78da4789ee637ede"]
        }, {
            "function": "OCA\\DAV\\Connector\\Sabre\\{closure}",
            "class": "OCA\\DAV\\Connector\\Sabre\\File",
            "type": "->",
            "args": ["*** sensitive parameters replaced ***"]
        }, {
            "file": "/var/www/nextcloud/lib/private/Files/Stream/HashWrapper.php",
            "line": 71,
            "function": "call_user_func",
            "args": [{
                "__class__": "Closure"
            }, "*** sensitive parameter replaced ***"]
        }, {
            "function": "stream_close",
            "class": "OC\\Files\\Stream\\HashWrapper",
            "type": "->",
            "args": []
        }, {
            "file": "/var/www/nextcloud/3rdparty/icewind/streams/src/Wrapper.php",
            "line": 132,
            "function": "fclose",
            "args": [null]
        }, {
            "file": "/var/www/nextcloud/lib/private/Files/Stream/HashWrapper.php",
            "line": 75,
            "function": "stream_close",
            "class": "Icewind\\Streams\\Wrapper",
            "type": "->",
            "args": []
        }, {
            "function": "stream_close",
            "class": "OC\\Files\\Stream\\HashWrapper",
            "type": "->",
            "args": []
        }, {
            "file": "/var/www/nextcloud/3rdparty/icewind/streams/src/Wrapper.php",
            "line": 132,
            "function": "fclose",
            "args": [null]
        }, {
            "file": "/var/www/nextcloud/lib/private/Files/Stream/HashWrapper.php",
            "line": 75,
            "function": "stream_close",
            "class": "Icewind\\Streams\\Wrapper",
            "type": "->",
            "args": []
        }, {
            "file": "/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
            "line": 319,
            "function": "stream_close",
            "class": "OC\\Files\\Stream\\HashWrapper",
            "type": "->",
            "args": []
        }, {
            "file": "/var/www/nextcloud/apps/dav/lib/Server.php",
            "line": 320,
            "function": "exec",
            "class": "Sabre\\DAV\\Server",
            "type": "->",
            "args": []
        }, {
            "file": "/var/www/nextcloud/apps/dav/appinfo/v2/remote.php",
            "line": 35,
            "function": "exec",
            "class": "OCA\\DAV\\Server",
            "type": "->",
            "args": []
        }, {
            "file": "/var/www/nextcloud/remote.php",
            "line": 167,
            "args": ["/var/www/nextcloud/apps/dav/appinfo/v2/remote.php"],
            "function": "require_once"
        }],
        "File": "/var/www/nextcloud/lib/private/Log/ErrorHandler.php",
        "Line": 91,
        "CustomMessage": "--"
    },
    "userAgent": "Mozilla/5.0 (Android) Nextcloud-android/3.13.1",
    "version": "19.0.4.2",
    "id": "5f8b113f613e3"

@askd77

This comment has been minimized.

@prismopensource

This comment has been minimized.

@j0yze
Copy link

j0yze commented Oct 21, 2020

I was able to fix it on my installation by manually apply some changes.
I found it in the German Nextcloud community board:
https://help.nextcloud.com/t/nextcloud-20-stable-kann-mit-offentlichen-links-nicht-uploaden-und-nicht-loschen/94471/6

@prismopensource

This comment has been minimized.

@simonspa

This comment has been minimized.

@AndyXheli

This comment has been minimized.

@gnodgl
Copy link

gnodgl commented Jun 12, 2021

I'm getting the same error( 20.0.9) ,I saw many people locate the tmp_dir which inspired me.So i checked out my tmp_dir and found that my permissions were satisfied but not enough space.So I clean up the tmp directory.Yeeeees, that seems to work for me.

@fool15982
Copy link

Hello there!

I am experiencing the same issue with snap Nextcloud version 21.0.1snap2 running on Ubuntu 18LTS.
I can use upload via WI when I am logged in as a user and sync via NC client is working properly but if I share a folder (with or without password) with write access only (like drop in only) the upload fails.
The issue seem to occure only when "upload only" is selected. If the sharing permission is set to upload and edit, it works as expected!

From the logs I can see:
[PHP] Error: Error: Cannot modify header information - headers already sent by (output started at /snap/nextcloud/28088/htdocs/3rdparty/sabre/http/lib/Sapi.php:132) at /snap/nextcloud/28088/htdocs/apps/dav/lib/Connector/Sabre/File.php#691 at <>

<>
OC\Log\ErrorHandler::onError(2, "Cannot modify h ... )", "/snap/nextcloud ... p", 691, {string: "X-Hash ... "})
/snap/nextcloud/28088/htdocs/apps/dav/lib/Connector/Sabre/File.php line 691
header("X-Hash-MD5: c8e ... f")
/snap/nextcloud/28088/htdocs/apps/dav/lib/Connector/Sabre/File.php line 189
OCA\DAV\Connector\Sabre\File->header("X-Hash-MD5: c8e ... f")
<>
OCA\DAV\Connector\Sabre\File->OCA\DAV\Connector\Sabre{closure}("*** sensitive parameters replaced ")
/snap/nextcloud/28088/htdocs/lib/private/Files/Stream/HashWrapper.php line 71
call_user_func(Closure {}, " sensitive parameter replaced ***")
<>
OC\Files\Stream\HashWrapper->stream_close()
/snap/nextcloud/28088/htdocs/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php line 95
fclose(null)
/snap/nextcloud/28088/htdocs/lib/private/Files/Stream/HashWrapper.php line 75
Icewind\Streams\Wrapper->stream_close()
<>
OC\Files\Stream\HashWrapper->stream_close()
/snap/nextcloud/28088/htdocs/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php line 95
fclose(null)
/snap/nextcloud/28088/htdocs/lib/private/Files/Stream/HashWrapper.php line 75
Icewind\Streams\Wrapper->stream_close()
/snap/nextcloud/28088/htdocs/3rdparty/sabre/dav/lib/DAV/Server.php line 321
OC\Files\Stream\HashWrapper->stream_close()
/snap/nextcloud/28088/htdocs/apps/dav/appinfo/v1/publicwebdav.php line 113
Sabre\DAV\Server->exec()
/snap/nextcloud/28088/htdocs/public.php line 81
require_once("/snap/nextcloud ... p")
PUT /public.php/webdav/Profilfoto.JPG
from 176.199.24.5 at 2021-06-20T21:18:03+00:00

The lastest updates are installed (OS & snap).

BR
Andre

@matejdro
Copy link

matejdro commented Jun 30, 2021

Another cause for this seems to be insufficient permissions. Folder that I tried to write to, was not writable by www-data. I fixed the permissions and it started working.

Better error messages would be appreciated.

@sbw
Copy link

sbw commented Jul 3, 2021

I believe it's important to note that the error message "Cannot modify header information - headers already sent by ..." clearly indicates that the error is produced by code that isn't exactly broken. Rather, the broken code ran earlier and produced the "headers already sent." What's broken is: The error produced by that earlier code is not recorded, and processing is allowed to continue until our secondary error message is produced.

For months, I've been meaning to do the work to consistently reproduce this problem, then dig into the code to find the code that caused the earlier error. I haven't done that, because I keep hoping one of the Nextcloud developers will take the time to do it. I'm sure a developer more familiar with the Nextcloud code can do it more quickly than I can.

I post this comment in the hope that it saves other Nextcloud users a bit of time: Many folks have generously taken the time to find workarounds and post them here. Several different workarounds, and I'm sure each works in a specific situation. But don't be discouraged if they don't work for you, because various un-caught errors trigger this secondary error, I believe.

Finally, I acknowledge that I may be wrong about this "secondary error" thing. It's based on my experience with PHP, not on any specific investigation of this Nextcloud error.

@gessel
Copy link

gessel commented Jul 8, 2021

For my install, the problem was the Ransomware protection plugin triggering on certain filename patterns. It seems to lock write after detecting filename patterns such as files ending in .dll and filenames including the sequence encrypted. Disabling the plugin resolved the problem for me. I found the problem by restarting the client and watching the errors in the log: errors such as the above appeared after the helpful plugin message, which was soon buried by the "cant modify header" errors as above, just as @sbw suggested.

@szaimen
Copy link
Contributor

szaimen commented Aug 8, 2021

Is this Issue still valid in NC21.0.4? If not, please close this issue. Thanks! :)

@altosch
Copy link
Author

altosch commented Aug 9, 2021

It seems to be gone in 21.0.3. Thank you.

@altosch altosch closed this as completed Aug 9, 2021
@dark-m0de
Copy link

The issue is stil valid in NC22.1.0

@altosch
Copy link
Author

altosch commented Aug 9, 2021

I haven't seen the error for a long time in my installation. But OK, reopened. Can anyone else confirm the issue in 21.0.3 or later?

@altosch altosch reopened this Aug 9, 2021
@DanScharon

This comment has been minimized.

@Mazvy
Copy link

Mazvy commented Aug 9, 2021

Can confirm the issue persists on 21.0.3

This issue on my server is seemingly only caused by iOS clients (via Nextcloud iOS app, auto upload). I think a few of these errors were generated by Android devices, but perhaps they actually dropped internet connections mid upload as it's extremely rare. Can also confirm this error is not generated by using the browser to upload files (at least with Firefox and Chrome on Windows machines).

It also seems that after an iOS device fails to upload more than a few files it stops auto syncing.

This might be a fluke, but it seems that on my server that this error rate is much lower with chunking set to the default 10mb, previously I ran 0 which increased upload speeds to my spinning rust main storage.

Edit: Not sure why the comment above is marked as off-topic. The error we're discussing is always accompanied by the filesize error.

@dark-m0de
Copy link

dark-m0de commented Aug 10, 2021

Although I can't say that this behaviour comes from specific files, I also encountered a series of multiple errors.
My environment is a new instance of NC22.1.0 and I currently try to synchronize a 100GB folder (small and large files) from my MacBook (official NC client) to the nextcloud instance.

When I just restarted the sync, there was a series of six errors:
#1: "Error: file_put_contents(/volume1/NextCloud-Data/...long file name....ppt.ocTransferId1595765278.part): failed to open stream: File name too long at /volume1/web/nextcloud/lib/private/Files/Storage/Local.php#282".

#2-3:
"Sabre\DAV\Exception: Error while copying file to target location (copied bytes: -1, expected filesize: 2470912 )"

#4-6: "Error: Cannot modify header information - headers already sent by (output started at /volume1/web/nextcloud/3rdparty/sabre/http/lib/Sapi.php:132) at /volume1/web/nextcloud/apps/dav/lib/Connector/Sabre/File.php#693"

I never recognized the file name too long error before. Maybe that is one source that afterwards leads to the header info failure message.

@Mazvy
Copy link

Mazvy commented Aug 10, 2021

Here's a filesize error created by an Android device, however there wasn't a "Cannot modify header information" error like before. Perhaps this is why someone here thought the issue was fixed? Perhaps the core issue of why files fail to upload is not related to the error we're discussing?

Also I haven't yet encountered a "File name too long" error.

{
   "reqId":"W24wxJfl5iSO1wWe7X7H",
   "level":3,
   "time":"2021-08-09T18:29:49+00:00",
   "remoteAddr":"-removed-",
   "user":"-removed-",
   "app":"no app in context",
   "method":"PUT",
   "url":"/remote.php/dav/uploads/-removed-/f6effccddbb4dd61458a99da46a8f586/0000000020480000-0000000030719999",
   "message":{
      "Exception":"Sabre\\DAV\\Exception\\BadRequest",
      "Message":"Expected filesize of 10240000 bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) 7053312 bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side.",
      "Code":0,
      "Trace":[
         {
            "file":"/var/www/nextcloud/apps/dav/lib/Connector/Sabre/Directory.php",
            "line":156,
            "function":"put",
            "class":"OCA\\DAV\\Connector\\Sabre\\File",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/apps/dav/lib/Upload/UploadFolder.php",
            "line":46,
            "function":"createFile",
            "class":"OCA\\DAV\\Connector\\Sabre\\Directory",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
            "line":1098,
            "function":"createFile",
            "class":"OCA\\DAV\\Upload\\UploadFolder",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php",
            "line":504,
            "function":"createFile",
            "class":"Sabre\\DAV\\Server",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php",
            "line":89,
            "function":"httpPut",
            "class":"Sabre\\DAV\\CorePlugin",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
            "line":472,
            "function":"emit",
            "class":"Sabre\\DAV\\Server",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
            "line":253,
            "function":"invokeMethod",
            "class":"Sabre\\DAV\\Server",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",
            "line":321,
            "function":"start",
            "class":"Sabre\\DAV\\Server",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/apps/dav/lib/Server.php",
            "line":332,
            "function":"exec",
            "class":"Sabre\\DAV\\Server",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/apps/dav/appinfo/v2/remote.php",
            "line":35,
            "function":"exec",
            "class":"OCA\\DAV\\Server",
            "type":"->"
         },
         {
            "file":"/var/www/nextcloud/remote.php",
            "line":167,
            "args":[
               "/var/www/nextcloud/apps/dav/appinfo/v2/remote.php"
            ],
            "function":"require_once"
         }
      ],
      "File":"/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php",
      "Line":246,
      "CustomMessage":"--"
   },
   "userAgent":"Mozilla/5.0 (Android) Nextcloud-android/3.16.1",
   "version":"21.0.3.1"
}

@simonspa
Copy link
Contributor

I believe we can close this ticket, as far as I understand the situation this error always appears when a Sabre endpoint received a malformed request, e.g. because the client went away and the connection broke. The relevant code is here:

https://github.com/nextcloud/3rdparty/blob/9719b46b7c61239adae3649751bbc2d510e9700a/sabre/http/lib/Sapi.php#L131-L133

which is triggered further up:

      $contentLength = $response->getHeader('Content-Length');
        if (null !== $contentLength) {
            // ...
        } else {
            file_put_contents('php://output', $body);
        }

So whenever the body of a response is not empty but somehow the content length is, the code attempts to simply dump the output onto the PHP stream - which fails because of a previously and already reported error.

I'm not versed enough in PHP to tell whether a

} elseif (!headers_sent()) {
    file_put_contents('php://output', $body);
}

would prevent this error while not breaking things. 🤷‍♂️

@Mazvy
Copy link

Mazvy commented Aug 12, 2021

@simonspa The issue is that clients on good connections, even on LAN in my case, fail to upload files small and large alike and in the case of iOS - auto sync breaks and stops uploading after encountering these errors.

There are circumstances where your thesis is correct, but this behavior happens regardless of connection health and seemingly effects iOS/Mac devices more than Windows/Android, at least in my experience. I've yet to encounter this type of error from an Android device on LAN, but iOS devices struggle and for the most part consistently fail to upload files.

@iDmple
Copy link

iDmple commented Aug 12, 2021 via email

@simonspa
Copy link
Contributor

@simonspa The issue is that clients on good connections, even on LAN in my case, fail to upload files small and large alike and in the case of iOS - auto sync breaks and stops uploading after encountering these errors.

There are circumstances where your thesis is correct, but this behavior happens regardless of connection health and seemingly effects iOS/Mac devices more than Windows/Android, at least in my experience. I've yet to encounter this type of error from an Android device on LAN, but iOS devices struggle and for the most part consistently fail to upload files.

Right, but that would still point to a problem further up in the stack rather than PHP code - or am I mistaken?

@Mazvy
Copy link

Mazvy commented Aug 12, 2021

Right, but that would still point to a problem further up in the stack rather than PHP code - or am I mistaken?

Your guess is as good as mine :) From my sample size it appears that iOS/MacOS devices encounter this specific issue much more frequently than other devices. Perhaps the core of this issue lies with those apps, libs they use or the OS architecture in general.

However it could also be more to do with the way PHP/Nextcloud deal with incoming data. However I haven't encountered an issue with specifically iOS/MacOS devices failing to upload files via PHP, ever. My money is either on Nextcloud Server or iOS/MacOS Nextcloud apps.

Edit: I'm also not running Nextcloud and any of it's dependencies (Apache, PHP, etc.) behind proxies or in containers, thus I'm ruling out that aspect of Nextcloud Server.

@iDmple
Copy link

iDmple commented Aug 12, 2021 via email

@Mazvy
Copy link

Mazvy commented Aug 12, 2021

In our case it only happened with specific files, independently of the OS used to upload them.The way it's configured by default isn't great.

Would you share what configuration changes you've made that eliminated this issue?

@iDmple
Copy link

iDmple commented Aug 12, 2021 via email

@sbw
Copy link

sbw commented Aug 12, 2021

Right, but that would still point to a problem further up in the stack rather than PHP code - or am I mistaken?

Yes, as I wrote earlier, "cannot modify header information" is typically a secondary error. The primary error caused some output to the HTML response body, so PHP is letting us know we can't send headers anymore.

I regret I never dug in to find that primary error, and I'm still running an older version of Nextcloud, so even if I find the primary error in that version, that info not apply to current versions.

I hope this comment isn't a waste of everyone's time. I hope it leads a more knowledgeable Nextcloud developer to try to reprouce the error in a current version and track down the primary error. If they have time. Or, if nobody is seeing "cannot modify header information" in a current version, or if we're confident the primary error was found and fixed, then this ticket should be closed.

@dark-m0de
Copy link

I support @sbw, seeing it as a secondary error. In my case, the "cannot modify header information" always occured together with another error. However, sometimes the primary error was unfortunately not visible in the log (e.g. upload timed out due to slow database performance).

@solracsf
Copy link
Member

Let's close this as a secondary error, fired only because another error has been fire previously (like, but not only, an aborted upload, failed to assembling chunkks, etc.).

If you face this error, please report the main error in a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap bug needs info
Projects
None yet
Development

No branches or pull requests