nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.51k stars 4.08k forks source link

[Bug]: Caldav limit tag on initial sync causes incorrect Caldav error response. #48678

Open JeroenBer opened 1 month ago

JeroenBer commented 1 month ago

⚠️ This issue respects the following points: ⚠️

Bug description

OneCalendar users are experiencing errors when syncing caldav calendars with Nextcloud. This used to be working.

As OneCalendar developer I tried to reproduce the problem and for the latest versions of 28,29 and 30 the Caldav response is no longer working correctly when doing a initial sync.

Hereby an overview of which versions are working correct/incorrect:

Steps to reproduce

Sync caldav calendar data:

Request data

<sync-collection xmlns="DAV:">
  <sync-token />
  <sync-level>1</sync-level>
  <limit>
    <nresults>100</nresults>
  </limit>
  <prop>
    <getetag />
  </prop>
</sync-collection>

Actual response data (507):

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
    <s:exception>Interne serverfout</s:exception>
    <s:message>
        De server was niet in staat je aanvraag te verwerken.       Stuur de hieronder afgebeelde technische details naar de serverbeheerder wanneer dit opnieuw gebeurt.       Meer details in de serverlogging,           </s:message>

    <s:technical-details>
        <s:remote-address>172.17.0.1</s:remote-address>
        <s:request-id>du8YMujFjQr6HIRmBFm1</s:request-id>

        </s:technical-details>
</d:error>

Expected behavior

According to https://tools.ietf.org/html/rfc6578#section-3.11 the caldav server does not need to support limit tag but in that case the following 507 response data is expected:

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException</s:exception>
  <s:message/>
  <d:number-of-matches-within-limits/>
</d:error>

Nextcloud Server version

28

Operating system

None

PHP engine version

None

Web server

None

Database engine version

None

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

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

Configuration report

No response

List of activated Apps

No response

Nextcloud Signing status

No response

Nextcloud Logs

No response

Additional info

Perhaps there has been a minor update/fix of SabreDav that caused this problem in the newer 28/29/30 versions ?

joshtrichards commented 1 month ago

<s:request-id>du8YMujFjQr6HIRmBFm1</s:request-id>

The nextcloud.log should have a stack trace or some logging associated with this request id since it's an internal server error (I believe). Happen to have it handy from one of the instances that isn't responding as expected?

Enabling debug mode should also populate technical-details with more info.

I haven't looked too closely, but so far the changes introduced via #47770 & #47805 align most closely with your findings.

kesselb commented 1 month ago

Thanks for your report, and sorry for the troubles.

I agree with Josh that likely #47770 and #47805 changed how we handle the UnsupportedLimitOnInitialSyncException.

JeroenBer commented 1 month ago

Hi, I reproduced and looked in the nextcloud.log. This was what came up:

{"reqId":"HXLFwXcaYbWcv9Fym23z","level":3,"time":"2024-10-14T18:45:34+00:00","remoteAddr":"172.17.0.1","user":"admin","app":"webdav","method":"REPORT","url":"/remote.php/dav/calendars/admin/personal/","message":"Exception thrown: OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException","userAgent":"curl/7.54","version":"30.0.0.14","exception":{"Exception":"OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException","Message":"","Code":0,"Trace":[{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Sync/Plugin.php","line":121,"function":"getChanges","class":"OCA\\DAV\\CalDAV\\Calendar","type":"->","args":[null,"1",100]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Sync/Plugin.php","line":62,"function":"syncCollection","class":"Sabre\\DAV\\Sync\\Plugin","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"Sabre\\DAV\\Sync\\{closure}","class":"Sabre\\DAV\\Sync\\Plugin","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":690,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["report",["*** sensitive parameters replaced ***","*** sensitive parameters replaced ***","*** sensitive parameters replaced ***"]]},{"file":"/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpReport","class":"Sabre\\DAV\\CorePlugin","type":"->","args":[["Sabre\\HTTP\\Request"],["Sabre\\HTTP\\Response"]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["method:REPORT",[["Sabre\\HTTP\\Request"],["Sabre\\HTTP\\Response"]]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->","args":[["Sabre\\HTTP\\Request"],["Sabre\\HTTP\\Response"]]},{"file":"/var/www/html/apps/dav/lib/Server.php","line":370,"function":"start","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/appinfo/v2/remote.php","line":19,"function":"exec","class":"OCA\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/remote.php","line":146,"args":["/var/www/html/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/apps/dav/lib/CalDAV/Calendar.php","Line":369,"message":"","exception":{},"CustomMessage":"Exception thrown: OCA\\DAV\\Exception\\UnsupportedLimitOnInitialSyncException"}}

It seems indeed the Caldav "UnsupportedLimitOnInitialSyncException".

Probably the changes in #47770 or #47805 changed this behavior and is now producing incorrect exception behavior for Caldav. In my opinion this is clearly a bug, and it might also potentially cause issues in other Caldav errors.

We are receiving more and more mails from people affected by this behavior. Is this something that can be fixed soon ?

kesselb commented 1 month ago

cc @artonge do you have a tip for us how to prevent the default exception handler to overwrite our exception?

artonge commented 1 month ago

Hmm, maybe we should display the exception for a given set of HTTP code. Probably here: https://github.com/nextcloud/server/blob/dc92218d6d3a53e6e8c825ed4efb080364259156/apps/dav/lib/Files/ErrorPagePlugin.php#L61-L88

Update that method to display or not the exception based on the HTTP code.

JeroenBer commented 1 month ago

Hi, Any news on this ? Can this be solved quickly for the next release ? More and more users of OneCalendar are mailing us about this problem in Nextcloud now. Currently there is no workaround and people cannot use their calendar in OneCalendar.

pampasadmin commented 4 weeks ago

The trouble with 30.0.1 is, that there is no switch back possible to 29.0.6 resp. 28.0.9. Therefore waiting for resolution is the only way forward.

ctosae commented 3 weeks ago

I have the same problem! Is it possible to install a specific version of Nextcloud AIO like 29.0.6? And... when will this issue be fixed @joshtrichards?

poek1 commented 3 weeks ago

I use the Android App OneCalender and get the Errormessage "This does not appear to be a valis CalDav server" when try to add my nextcloud account to it. It does work well with Thunderbird at Mac and Win. Would be nice to get it fixxed soon.

Nextcloud 29.0.3 OneCalender 5.6.0

I am only a user, my Nextcloudadmin gave me that link to Github.

Update: my Admin updated to 29.0.6 and its not working (Server got restart)

emaas commented 1 week ago

I have multiple users that are running into this issue. My Nextcloud automatically get's updated every night to keep all the maintenance manageable. When you are already connected to OneCalender everything works properly. It is just with the initial setup that it is not working.

nouse4it commented 1 week ago

I have the exact same problem. I had to reset my phone and start over with the calendar setup. Now I can´t get to run because of the limit error. When is this going to be fixed? According to google, this problem occurred several times already in the past Nextcloud versions, f.e. ---> https://github.com/nextcloud/server/issues/18490

pampasadmin commented 1 week ago

On my Android tablet and on win11 the account setup seems to work. However syncing fails.

bitsky6 commented 3 days ago

Any news? Nextcloud calendar currently unusable with any client. Thanks

VEF-Admin commented 2 days ago

The error is still present with the latest version of NC (30.0.2) and OneCalendar (5.6.0). Is there any guess when a patch/update/workaround will be available? Thanks!

andreyvb commented 1 day ago

I've tried several apps that sync the calendar over caldav - none work with NextCloud right now.

Minstrel27 commented 15 hours ago

I did some further research and testing, and what I’ve found is that there is a bug in later versions of Nextcloud that prevents INITIAL syncing of davx calendars. Those versions are 28.0.10 or higher, 29.0.7 or higher, and all versions of 30. Calendars where the initial sync was done in prior versions continue to sync correctly in the latest versions.

I was able to confirm this by going back and installing version 29.0.6, migrating all my data and settings, syncing the calendars, then upgrading to 30.0.2 and everything worked correctly. Obviously doing a new install of 29.0.6 each time I want to add a new user with all that entails is a task I don’t want to do every week, but at least I have an option.

Hopefully this will be fixed in the near future.