Contacts: Wrong Etag return from server prevents modifications from being saved

Created on 15 Jul 2017  ·  35Comments  ·  Source: nextcloud/contacts

Steps to reproduce

  1. Open the Contacts app
  2. Perform any kind of change to a contact or add a new contact
  3. Reload the page afterwards

Expected behaviour

The information typed in any contact should be saved

Actual behaviour

Information typed in the lost 5-10 seconds before refreshing the page is lost

Operating system: Debian 9

Web server: Apache 2.4.25

Database: MariaDB 10.1.23

PHP version: 5.6.30

Nextcloud version: 12.0.0

Contacts version: 1.5.3

**Updated from an older Nextcloud or fresh install: Migrated from ownCloud 10 to Nextcloud 12

Login as admin user into your Nextcloud and access 
http://example.com/index.php/settings/integrity/failed 
paste the results here.

No errors have been found.

List of activated apps:
Enabled:

  • activity: 2.5.2
  • bruteforcesettings: 1.0.2
  • calendar: 1.5.3
  • comments: 1.2.0
  • contacts: 1.5.3
  • dav: 1.3.0
  • federatedfilesharing: 1.2.0
  • files: 1.7.2
  • files_external: 1.3.0
  • files_pdfviewer: 1.1.1
  • files_sharing: 1.4.0
  • files_texteditor: 2.4.1
  • files_trashbin: 1.2.0
  • files_versions: 1.5.0
  • files_videoplayer: 1.1.0
  • firstrunwizard: 2.1
  • gallery: 17.0.0
  • logreader: 2.0.0
  • lookup_server_connector: 1.0.0
  • news: 11.0.5
  • nextcloud_announcements: 1.1
  • notifications: 2.0.0
  • oauth2: 1.0.5
  • password_policy: 1.2.2
  • provisioning_api: 1.2.0
  • registration: 0.2.5
  • serverinfo: 1.2.0
  • sharebymail: 1.2.0
  • survey_client: 1.0.0
  • systemtags: 1.2.0
  • theming: 1.3.0
  • twofactor_backupcodes: 1.1.1
  • twofactor_totp: 1.3.0
  • updatenotification: 1.2.0
  • workflowengine: 1.2.0

**Nextcloud configuration:**
{
    "system": {
        "updatechecker": false,
        "instanceid": "oc45dii8hdi1",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "cloud.gnax.io"
        ],
        "datadirectory": "\/home\/cloud\/data",
        "overwrite.cli.url": "https:\/\/cloud.gnax.io",
        "dbtype": "mysql",
        "version": "12.0.0.29",
        "dbname": "gnax.io_cloud",
        "dbhost": "localhost",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "logtimezone": "UTC",
        "installed": true,
        "mail_smtpmode": "smtp",
        "mail_smtpsecure": "ssl",
        "mail_from_address": "noreply",
        "mail_domain": "gnax.io",
        "mail_smtpauthtype": "LOGIN",
        "mail_smtpauth": 1,
        "mail_smtphost": "letmein.gnax.io",
        "mail_smtpport": "465",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "memcache.local": "\\OC\\Memcache\\Redis",
        "filelocking.enabled": true,
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "localhost",
            "port": 6379
        },
        "loglevel": 2,
        "mysql.utf8mb4": true,
        "maintenance": false,
        "theme": "",
        "appstore.experimental.enabled": true
    }
}

**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: Tried in both Chrome and Edge

Operating system: Windows 10


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

3. to review bug high

All 35 comments

Not sure if it is related, but I've found something else acting up regarding contacts.
If I enable the feature: "Allow username autocompletion in share dialog. If this is disabled the full username needs to be entered." the search contacts now gives me an error:
image

In the logs I'm getting the following:
Doctrine\DBAL\Exception\DriverException: An exception occurred while executing 'SELECT c.carddata, c.uri FROM oc_cards c WHERE c.id IN (SELECT DISTINCT cp.cardid FROM oc_cards_properties cp WHERE (cp.addressbookid = ?) AND (cp.name = ?) AND (cp.value COLLATE utf8mb4_general_ci LIKE ?))' with params ["18", "FN", "%%"]: SQLSTATE[42000]: Syntax error or access violation: 1253 COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'
/home/cloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php - line 128: Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
/home/cloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php - line 855: Doctrine\DBAL\DBALException driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'SELECT c.car...', Array) /home/cloud/lib/private/DB/Connection.php - line 192: Doctrine\DBAL\Connection->executeQuery('SELECTc.car...', Array, Array, NULL)
/home/cloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php - line 206: OC\DB\Connection->executeQuery('SELECT c.`car...', Array, Array)
/home/cloud/lib/private/DB/QueryBuilder/QueryBuilder.php - line 213: Doctrine\DBAL\Query\QueryBuilder->execute()
/home/cloud/apps/dav/lib/CardDAV/CardDavBackend.php - line 892: OC\DB\QueryBuilder\QueryBuilder->execute()
/home/cloud/apps/dav/lib/CardDAV/AddressBookImpl.php - line 95: OCA\DAV\CardDAV\CardDavBackend->search('18', '', Array)
/home/cloud/lib/private/ContactsManager.php - line 45: OCA\DAV\CardDAV\AddressBookImpl->search('', Array, Array)
/home/cloud/lib/private/Contacts/ContactsMenu/ContactsStore.php - line 51: OC\ContactsManager->search('', Array)
/home/cloud/lib/private/Contacts/ContactsMenu/Manager.php - line 59: OC\Contacts\ContactsMenu\ContactsStore->getContacts(Object(OC\User\User), NULL)
/home/cloud/core/Controller/ContactsMenuController.php - line 60: OC\Contacts\ContactsMenu\Manager->getEntries(Object(OC\User\User), NULL)
[internal function] OC\Core\Controller\ContactsMenuController->index(NULL)
/home/cloud/lib/private/AppFramework/Http/Dispatcher.php - line 160: call_user_func_array(Array, Array)
/home/cloud/lib/private/AppFramework/Http/Dispatcher.php - line 90: OC\AppFramework\Http\Dispatcher->executeController(Object(OC\Core\Controller\ContactsMenuController), 'index')
/home/cloud/lib/private/AppFramework/App.php - line 114: OC\AppFramework\Http\Dispatcher->dispatch(Object(OC\Core\Controller\ContactsMenuController), 'index')
/home/cloud/lib/private/AppFramework/Routing/RouteActionHandler.php - line 47: OC\AppFramework\App main('ContactsMenuCon...', 'index', Object(OC\AppFramework\DependencyInjection\DIContainer), Array)
[internal function] OC\AppFramework\Routing\RouteActionHandler->__invoke(Array)
/home/cloud/lib/private/Route/Router.php - line 299: call_user_func(Object(OC\AppFramework\Routing\RouteActionHandler), Array)
/home/cloud/lib/base.php - line 1000: OC\Route\Router->match('/contactsmenu/c...')
/home/cloud/index.php - line 40: OC handleRequest()
{main}

The "There was an error loading your contacts" does not seem to have been related, as it was fixed with a maintenance:repair.
However the original issue remains the same.

I would love a "save" button, to make sure that everything is saved before switching pages.

I remember me adding a save button not long ago!! Need to check this!

Edit, there is one in case of property failure. https://github.com/nextcloud/contacts/blob/master/templates/contactDetails.html#L27

Nevertheless, I'm intrigued by the autosave misfunction. Works fine here. Do you get any errors in the console when you type?

Could be great to add a modal in case of page switching when the contact isn't saved!

There are no errors in the console.
If you'd like to try it out, I can create an account for you in my environment.

Well, maybe the contact you're editing is corrupted and refused to be saved on the server side.
Have you tried with a new contact and changing its name for example? On my install, the save occurs like 500ms after I stopped typing.

I've tested with another contact and even another account and reproduced it.
If I don't leave the contact page for 20-30 seconds, it does save it.

Strange, could you set an account for me then? :)

Nevermind. Even after waiting for a minute on the page after entering information and refreshing the page, the information wasn't saved.
Sure, do you have an email address I can send the information to? :)

Check your inbox

You got a 412 Error.
"An If-Match header was specified, but none of the specified the ETags matched"

https://github.com/nextcloud/contacts/issues/135

Do you know what could be causing this?

It seems to be an old bug! Will look into it, some people seems to have it, I'll keep you updated. :)

Okay, did some digging!
The first edit sent to the server is saved!
After that all of the other ones are sending a null Etag request (if-match)!

capture d ecran_2017-07-26_17-45-04
capture d ecran_2017-07-26_17-45-16

Dug more, the server isn't returning an etag header.
@GnaXi What version of nextcloud are you using?

EDIT: NC12, my bad.
This is strange!

@LukasReschke , any clue? Seems related to this? https://github.com/nextcloud/server/pull/1513

@GnaXi Can you replace ETag by OC-ETag
on this file on your server https://github.com/nextcloud/contacts/blob/master/js/services/contact_service.js#L249 ?

@skjnldsv I have no folder in js called services. Could that be an issue? :P
Only folders in /apps/contacts/js are dav, public and vendor.

@GnaXi all the js files are merged into the public folder. You need to look for the Etag line. :)

@skjnldsv That seems to have done the trick! Everything is instantly saved now! :D

Good to hear! 😉
But, strange nonetheless.

Removing and creating a new addressbook seems to fix the problem too!

I did try that before replacing ETag by OC-ETag and that was not the case for me.

Someone had the same issue on my server. Will report if exporting and reimporting works.

so when are we going to have an official fix for this issue?

@tiggerfan feel free to create a pull request. This is an open source application.

how is this an enhancement. it seems to be a bug since it doesn't work.
also i'm not a developer so i won't be creating a pull request.

@tiggerfan It is indeed.
Too bad you're not a dev, could have been nice to have some help on this!

@skjnldsv I could PR, but I tried your fix, and I still get the following error:

Content Security Policy: The page’s settings blocked the loading of a resource at self (“script-src 'nonce-NUk5U083NHMxNE5yaTVoeEEvTVJ1OWpaOC92RWxsVHhwNFYvSXlPMURnbz06MGZjVGEraG80OFFhektBbmQ2RjdnL09XeTdDcTRCMjdrOUlRY2ttRmVHYz0=' 'unsafe-eval'”). Source: ondrop attribute on INPUT element.

I modified the 2 following lines:

newContact.setETag(xhr.getResponseHeader('OC-ETag'));
...
var newEtag = xhr.getResponseHeader('OC-ETag');

But no success :/

@pierreozoux @GnaXi
Please test https://github.com/nextcloud/contacts/pull/402

Was this fixed as of 2.0.1? I am having the same issues while editing contacts
Google js chrome:
401 (Unauthorized)
412 (Precondition failed)
501 sometimes

Nextcloud chrome client says:
Contact could not be saved

apache2: (sometimes, fixed when changed memory-max to 4G)
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 77 bytes)

I changed the ETag to OC-ETag with no success as suggested earlier

No it's not released yet

Is it live yet? I noticed this happens to any of my contacts that have data that doesn't display in the contacts app, case in point what I wrote here about anniversary data: https://github.com/nextcloud/contacts/issues/135#issuecomment-359570564

@xenithorb not released, you can try the nightlies if you want tough

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kangaroo72 picture kangaroo72  ·  4Comments

keunes picture keunes  ·  4Comments

Dennis1993 picture Dennis1993  ·  5Comments

caugner picture caugner  ·  3Comments

Peque picture Peque  ·  3Comments