Skip to content

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

Closed

Description

@altosch

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) ...

Activity

  1. added
    0. Needs triagePending check for reproducibility or if it fits our roadmap
    on Aug 31, 2020
  2. altosch commented on Sep 4, 2020

    @altosch
    Author
  3. Shuvi-Hub commented on Sep 6, 2020

    @Shuvi-Hub
  4. AndyXheli commented on Sep 6, 2020

    @AndyXheli
  5. Shuvi-Hub commented on Sep 6, 2020

    @Shuvi-Hub
  6. yewkay commented on Sep 11, 2020

    @yewkay
  7. altosch commented on Sep 11, 2020

    @altosch
    Author

    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

  8. csgt01 commented on Sep 18, 2020

    @csgt01
  9. papezg commented on Sep 18, 2020

    @papezg
  10. xmzl commented on Sep 21, 2020

    @xmzl
  11. papezg commented on Sep 22, 2020

    @papezg

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

  12. boyi01 commented on Oct 2, 2020

    @boyi01

    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....

  13. PieterGit commented on Oct 7, 2020

    @PieterGit

    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).

  14. xmzl commented on Oct 8, 2020

    @xmzl

    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

  15. 82 remaining items

  16. Mazvy commented on Aug 9, 2021

    @Mazvy

    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.

  17. dark-m0de commented on Aug 10, 2021

    @dark-m0de

    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.

  18. Mazvy commented on Aug 10, 2021

    @Mazvy

    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"
    }
    
  19. simonspa commented on Aug 12, 2021

    @simonspa
    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. 🤷‍♂️

  20. Mazvy commented on Aug 12, 2021

    @Mazvy

    @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.

  21. iDmple commented on Aug 12, 2021

    @iDmple
  22. simonspa commented on Aug 12, 2021

    @simonspa
    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?

  23. Mazvy commented on Aug 12, 2021

    @Mazvy

    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.

  24. iDmple commented on Aug 12, 2021

    @iDmple
  25. Mazvy commented on Aug 12, 2021

    @Mazvy

    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?

  26. iDmple commented on Aug 12, 2021

    @iDmple
  27. sbw commented on Aug 12, 2021

    @sbw

    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.

  28. dark-m0de commented on Aug 19, 2021

    @dark-m0de

    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).

  29. solracsf commented on Aug 24, 2021

    @solracsf
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triagePending check for reproducibility or if it fits our roadmapbugneeds info

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions