sabre-io / Baikal

Baïkal is a Calendar+Contacts server
https://sabre.io/baikal/
GNU General Public License v3.0
2.44k stars 282 forks source link

Sabre\DAV\Exception\InvalidSyncToken: Invalid or unknown sync token #1202

Open onxipole opened 10 months ago

onxipole commented 10 months ago

Hello everyone and sorry if this issue has already been documented.

I have repeated errors of the same kind in my php error log, and the sync process between client and server doesn't work :

[29-Sep-2023 10:35:00 Europe/Paris] Sabre\DAV\Exception\InvalidSyncToken: Invalid or unknown sync token in /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Sync/Plugin.php:116 Stack trace:

0 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Sync/Plugin.php(62): Sabre\DAV\Sync\Plugin->syncCollection()

https://github.com/sabre-io/dav/pull/1 /home/mydomain/public_html/vendor/sabre/event/lib/WildcardEmitterTrait.php(89): Sabre\DAV\Sync\Plugin->Sabre\DAV\Sync{closure}() https://github.com/sabre-io/dav/pull/2 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/CorePlugin.php(685): Sabre\DAV\Server->emit() https://github.com/sabre-io/dav/pull/3 /home/mydomain/public_html/vendor/sabre/event/lib/WildcardEmitterTrait.php(89): Sabre\DAV\CorePlugin->httpReport() https://github.com/sabre-io/dav/pull/4 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Server.php(472): Sabre\DAV\Server->emit() https://github.com/sabre-io/dav/pull/5 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Server.php(253): Sabre\DAV\Server->invokeMethod() https://github.com/sabre-io/dav/pull/6 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Server.php(321): Sabre\DAV\Server->start() https://github.com/sabre-io/dav/pull/7 /home/mydomain/public_html/Core/Frameworks/Baikal/Core/Server.php(119): Sabre\DAV\Server->exec() https://github.com/sabre-io/dav/pull/8 /home/mydomain/public_html/html/dav.php(69): Baikal\Core\Server->start() https://github.com/sabre-io/dav/pull/9 {main}

I tried to update a contact (or add a new one), it stays on the client but doesn't record in the server, meaning it is not available for other clients.

The section it is referring to is that one :

$syncToken = $report->syncToken; if (!is_null($syncToken)) { // Sync-token must start with our prefix if (self::SYNCTOKEN_PREFIX !== substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX))) { throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token'); }

By performing searches on the Internet, I found a post with this workaround :

Since I really wanted the sync to work, I hacked my own system as follows:
After https://github.com/sabre-io/dav/blob/3.2/lib/DAV/Sync/Plugin.php#L119 (which is in lib/composer/sabre/dav/lib/DAV/Sync/Plugin.php) I added the following.
Definitely not a final solution; use at your own risk, I don't know the cardDAV specs nor the ownCloud system.

    $syncToken = $report->syncToken;
    // very crude macOS Mojave (10.14) Contacts sync "fix"
    // @see https://github.com/owncloud/core/issues/30820
    if ( \preg_match('/^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}$/', $syncToken) ) {
      $syncToken = null;
    }

ownCloud now just outputs the full REPORT and the contacts app syncs correctly (as far as I have tested it with ownCloud, macOS and my Android phone).

What to think about this ?

Mac OS 10.13.6 DEBIAN 10 - Baïkal 0.9.3

Thanks everyone !