contacts icon indicating copy to clipboard operation
contacts copied to clipboard

[PHP] Error: Undefined offset: 0 at /var/www/html/nextcloud/apps/contacts/lib/Service/SocialApiService.php#184

Open Githopp192 opened this issue 2 years ago • 43 comments

Describe the bug

There PHP-Errors into the LOG:

[PHP] Error: Undefined offset: 0 at /var/www/html/nextcloud/apps/contacts/lib/Service/SocialApiService.php#184
/var/www/html/nextcloud/apps/contacts/lib/Service/SocialApiService.php - line 184:

OC\Log\ErrorHandler::onError()

/var/www/html/nextcloud/apps/contacts/lib/Service/SocialApiService.php - line 410:

OCA\Contacts\Service\SocialApiService->updateContact("*** sensiti ... *")

/var/www/html/nextcloud/apps/contacts/lib/Cron/SocialUpdate.php - line 56:

OCA\Contacts\Service\SocialApiService->updateAddressbooks("*** sensiti ... *")

/var/www/html/nextcloud/lib/public/BackgroundJob/Job.php - line 79:

OCA\Contacts\Cron\SocialUpdate->run()

/var/www/html/nextcloud/lib/public/BackgroundJob/QueuedJob.php - line 47:

OCP\BackgroundJob\Job->execute()

/var/www/html/nextcloud/cron.php - line 150:

OCP\BackgroundJob\QueuedJob->execute()

Steps to reproduce

  1. Go to 'nextcloud.log'
  2. Click on 'logging'
  3. Scroll to the last php-error
  4. See PHP-Error

Expected behavior

there shoul be no PHP-errors

Actual behavior

There are PHP-Errors coming from contacts app. The sequence is about 20 Times in one minute.

I think the PHP-errors are coming only from the only one/same user

Other users seems not to be affected.

Contact version

contacts: 4.1.0

Operating system

Red Hat Enterprise Linux release 8.5

PHP engine version

PHP 7.4

Web server

Apache (supported)

Database

MariaDB

Operating system

Red Hat Enterprise Linux release 8.5

List of activated Apps

Enabled:
  - accessibility: 1.9.0
  - activity: 2.15.0
  - analytics: 4.2.1
  - announcementcenter: 6.1.1
  - apporder: 0.15.0
  - audioplayer: 3.3.0
  - audioplayer_sonos: 1.3.0
  - bookmarks: 10.2.1
  - breezedark: 23.2.1
  - bruteforcesettings: 2.4.0
  - calendar: 3.2.2
  - circles: 23.1.0
  - cloud_federation_api: 1.6.0
  - cms_pico: 1.0.18
  - collectives: 1.0.0
  - comments: 1.13.0
  - contacts: 4.1.0
  - contactsinteraction: 1.4.0
  - cookbook: 0.9.11
  - cospend: 1.4.6
  - dashboard: 7.3.0
  - data_request: 1.10.0
  - dav: 1.21.0
  - deck: 1.6.1
  - dicomviewer: 1.2.3
  - documentserver_community: 0.1.12
  - drawio: 1.0.2
  - electronicsignatures: 1.10.1
  - end_to_end_encryption: 1.9.1
  - event_update_notification: 1.5.0
  - extract: 1.3.3
  - federatedfilesharing: 1.13.0
  - federation: 1.13.0
  - files: 1.18.0
  - files_antivirus: 3.2.2
  - files_automatedtagging: 1.13.0
  - files_downloadactivity: 1.13.0
  - files_external: 1.15.0
  - files_markdown: 2.3.6
  - files_mindmap: 0.0.26
  - files_pdfviewer: 2.4.0
  - files_photospheres: 1.23.0
  - files_rightclick: 1.2.0
  - files_sharing: 1.15.0
  - files_trashbin: 1.13.0
  - files_versions: 1.16.0
  - files_videoplayer: 1.12.0
  - firstrunwizard: 2.12.0
  - forms: 2.5.0
  - gpxpod: 4.3.0
  - groupfolders: 11.1.2
  - health: 1.5.0
  - impersonate: 1.10.0
  - integration_discourse: 1.0.2
  - integration_dropbox: 1.0.4
  - integration_github: 1.0.2
  - integration_gitlab: 1.0.3
  - integration_google: 1.0.6
  - integration_jira: 1.0.2
  - integration_mastodon: 1.0.2
  - integration_moodle: 1.0.2
  - integration_openproject: 1.0.6
  - integration_reddit: 1.0.3
  - integration_suitecrm: 1.0.3
  - integration_twitter: 1.0.2
  - integration_zammad: 1.0.3
  - logreader: 2.8.0
  - lookup_server_connector: 1.11.0
  - maps: 0.1.10
  - nextcloud_announcements: 1.12.0
  - notes: 4.3.1
  - notifications: 2.11.1
  - oauth2: 1.11.0
  - onlyoffice: 7.3.2
  - passman: 2.4.0
  - password_policy: 1.13.0
  - photos: 1.5.0
  - polls: 3.5.4
  - privacy: 1.7.0
  - provisioning_api: 1.13.0
  - quicknotes: 0.7.3
  - quota_warning: 1.14.0
  - rainloop: 7.2.2
  - ransomware_protection: 1.13.0
  - recommendations: 1.2.0
  - serverinfo: 1.13.0
  - settings: 1.5.0
  - sharebymail: 1.13.0
  - socialsharing_diaspora: 2.5.0
  - socialsharing_email: 2.5.0
  - socialsharing_facebook: 2.5.0
  - socialsharing_twitter: 2.5.0
  - spreed: 13.0.5
  - support: 1.6.0
  - systemtags: 1.13.0
  - talk_matterbridge: 1.23.2
  - tasks: 0.14.4
  - terms_of_service: 1.9.3
  - text: 3.4.1
  - theming: 1.14.0
  - timemanager: 0.2.9
  - twofactor_backupcodes: 1.12.0
  - twofactor_totp: 6.2.0
  - updatenotification: 1.13.0
  - user_status: 1.3.1
  - video_converter: 1.0.4
  - viewer: 1.7.0
  - weather_status: 1.3.0
  - welcome: 1.0.1
  - workflow_media_converter: 1.3.6
  - workflow_ocr: 1.23.2
  - workflow_pdf_converter: 1.8.0
  - workflow_script: 1.8.0
  - workflowengine: 2.5.0
Disabled:
  - admin_audit: 1.6.0
  - audioplayer_editor: 0.3.0
  - drop_account: 2.0.0
  - encryption
  - external: 3.10.2
  - files_3d: 0.5.0
  - files_accesscontrol: 1.13.0
  - files_external_onedrive: 1.1.0
  - files_fulltextsearch: 23.0.1
  - flow_notifications: 1.2.0
  - flowupload: 1.1.3
  - fulltextsearch: 23.0.0
  - fulltextsearch_elasticsearch: 23.0.0
  - gpxedit: 0.0.14
  - gpxmotion: 0.1.0
  - integration_onedrive: 1.1.2
  - integration_whiteboard: 0.0.14
  - issuetemplate: 0.7.0
  - joplin: 0.0.25
  - ojsxc: 5.0.0
  - passwords: 2022.4.10
  - podcast: 0.3.1
  - registration: 1.4.0
  - side_menu: 2.3.5
  - social: 0.4.2
  - socialsharing_googleplus: 1.0.4
  - survey_client: 1.3.0
  - talked: 0.3.0
  - user_ldap
  - weather: 1.7.6

Nextcloud Signing status

No errors have been found.

Configuration report

{
    "system": {
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "filelocking.enabled": true,
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "dbindex": 0,
            "timeout": 1.5,
            "password": "***REMOVED SENSITIVE VALUE***"
        },
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "xxx",
            "xxx"
        ],
        "overwrite.cli.url": "https:\/\/xxxx",
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "htaccess.RewriteBase": "\/",
        "overwriteprotocol": "https",
        "dbtype": "mysql",
        "version": "23.0.3.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,
        "maintenance": false,
        "theme": "",
        "loglevel": 2,
        "auth.bruteforce.protection.enabled": true,
        "check_for_working_htaccess": true,
        "updater.release.channel": "stable",
        "data-fingerprint": "xxxx",
        "logfile": "\/xxx\/log\/nextcloud.log",
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpmode": "smtp",
        "mail_smtpauthtype": "LOGIN",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpsecure": "xxx",
        "mail_smtpauth": 1,
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "xxx",
        "session_lifetime": 1200,
        "session_keepalive": false,
        "logtimezone": "xxxx",
        "default_phone_region": "xxx",
        "knowledgebaseenabled": false,
        "log_rotate_size": xxx,
        "mail_sendmailmode": "smtp",
        "app_install_overwrite": [
            "passman",
            "dicomviewer",
            "radio",
            "cookbook",
            "health"
        ]
    }
}

Additional info

No response

Githopp192 avatar Apr 24 '22 20:04 Githopp192

Thank you for reporting. I could not reproduce this error. If you have more information, it would help me to search for the issue. You can deactivate the avatar download function in the settings menu of the address book in order to find out from which user this comes. Then it would be interesting if that user does have contacts in his or her address book.

call-me-matt avatar Apr 24 '22 20:04 call-me-matt

i now who the user is .. it affects only this one user i think .. i not see those messages from other users. i don't think this user has got contacts in his address book.

To check this .. i think i'd need to run a sql statement .. do you know the command for it by hand ? (for a/this specific user) ?

Githopp192 avatar Apr 24 '22 21:04 Githopp192

Just to be sure, is it possible to ask her or him to add a contact to see if this gets rid of the error messages? If it does not help, you can ask to deselect the checkbox in the addressbook settings to be certain the errors are coming from that user

call-me-matt avatar Apr 24 '22 22:04 call-me-matt

i'm very sure the errors are coming from this user only.

ScreenShot244

All these messages are coming from the same user.

I wrote a mail to the user, that he could try the steps you proposed.

Githopp192 avatar Apr 26 '22 11:04 Githopp192

I set up a fresh nextcloud instance with two users, both without contacts, and activated the social sync function for them. I could not reproduce this error.

So we need to look deeper: Can you take a look at your scheduled cron-jobs for the contacts-App? SELECT * FROM jobs WHERE class LIKE "%Contacts%"; Take a look if the arguments are valid user/address book/contact id combinations.

call-me-matt avatar Apr 26 '22 20:04 call-me-matt

i did replace 'jobs' with 'nextcloud.oc_jobs' :

ScreenShot248

Githopp192 avatar Apr 28 '22 06:04 Githopp192

Can you check if that is an existing user? And also if the contact exists?

call-me-matt avatar Apr 28 '22 08:04 call-me-matt

you mean - User xxx ? yes, this user is an existing user, but not that user, who is affected.

btw - in the meantime - the affected user does not use the Cloud anymore - so i did remove this user.

Just saw, that the error persists - now affecting another user. This user has no contacts defined for sure.

Error PHP Error: Undefined offset: 0 at /var/www/html/nextcloud/apps/contacts/lib/Service/SocialApiService.php#184 /var/www/html/nextcloud/apps/contacts/lib/Service/SocialApiService.php - line 184:

OC\Log\ErrorHandler::onError()

/var/www/html/nextcloud/apps/contacts/lib/Service/SocialApiService.php - line 410:

OCA\Contacts\Service\SocialApiService->updateContact("*** sensiti ... *")

/var/www/html/nextcloud/apps/contacts/lib/Cron/SocialUpdate.php - line 56:

OCA\Contacts\Service\SocialApiService->updateAddressbooks("*** sensiti ... *")

/var/www/html/nextcloud/lib/public/BackgroundJob/Job.php - line 79:

OCA\Contacts\Cron\SocialUpdate->run()

/var/www/html/nextcloud/lib/public/BackgroundJob/QueuedJob.php - line 47:

OCP\BackgroundJob\Job->execute()

/var/www/html/nextcloud/cron.php - line 150:

OCP\BackgroundJob\QueuedJob->execute()

Githopp192 avatar May 01 '22 13:05 Githopp192

this is a mystery to me. In order to come to line 410 (where the error is coming from), there must be contacts - as there is a "for-each-contact"-loop in line 400. So for each contact the update process is called, but then the search in line 184 returns no results. Shared and system address books are already filtered out beforehand, so I am puzzled what case I have missed. Having no contacts is not the reason for this, maybe deactivated address books? Can you share more about your setup?

call-me-matt avatar May 02 '22 18:05 call-me-matt

Debian 11.3, apache2, nextcloud 22.2.7 . After full-upgrade of debian 10 to debian 11 which includes an upgrade of php7.3 to php7.4, I observe the same stacktrace as @Githopp192 . Also the user xxx in the nextcloud.log is not the same user as yyyyyyy in the oc_jobs table. Somtimes the offsetContact is null.

MariaDB [nextcloud]>  SELECT * FROM oc_jobs WHERE class LIKE "%Contacts%";
+-------+--------------------------------------------------+-------------------------------------------------------------------+...
| id    | class                                            | argument                                                          |...
+-------+--------------------------------------------------+-------------------------------------------------------------------+...
|  3991 | OCA\Circles\Cron\ContactsExistingShares          | null                                                              |...
|  5311 | OCA\Contacts\Cron\SocialUpdateRegistration       | null                                                              |...
|  6488 | OCA\ContactsInteraction\BackgroundJob\CleanupJob | null                                                              |...
| 17919 | OCA\Contacts\Cron\SocialUpdate                   | {"userId":"yyyyyyy","offsetBook":"contacts","offsetContact":null} |...
+-------+--------------------------------------------------+-------------------------------------------------------------------+...

Both mentioned users have contacts in "contacts" The addressbooks are active, some readonly shared addressbooks exist.

ressit avatar May 02 '22 19:05 ressit

this is a mystery to me. In order to come to line 410 (where the error is coming from), there must be contacts - as there is a "for-each-contact"-loop in line 400. So for each contact the update process is called, but then the search in line 184 returns no results. Shared and system address books are already filtered out beforehand, so I am puzzled what case I have missed. Having no contacts is not the reason for this, maybe deactivated address books? Can you share more about your setup?

@matt - which information do you need exactly ?

Githopp192 avatar May 02 '22 19:05 Githopp192

which information do you need exactly ?

I need to reproduce the errors. Currently I did not succeed in that. Only after knowing what is happening, I can fix the error. Maybe the error appears always for a certain type of users? I need more help in reproducing the issues here.

Sometimes the offsetContact is null.

That is OK, it is null in the beginning and if the job is not finished, it will be continued with an offsetContact in the next background job to spare resources.

@skjnldsv do we have a development environment with php7.4 by chance?

call-me-matt avatar May 02 '22 20:05 call-me-matt

@skjnldsv do we have a development environment with php7.4 by chance?

Plenty are using 7.4 yes? Not sure I get the question :see_no_evil:

skjnldsv avatar May 02 '22 20:05 skjnldsv

@skjnldsv do we have a development environment with php7.4 by chance?

Plenty are using 7.4 yes? Not sure I get the question 🙈

i've got a vbox vm .. running PHP Version => 7.4.28, NC: 24.0.0 RC2

Did create a new contacts entry .. but do not see similar errors into the log

Githopp192 avatar May 03 '22 09:05 Githopp192

Another idea: If the user has no contacts but entries in the recently contacted address book, could this be leading to this issue?

call-me-matt avatar May 03 '22 10:05 call-me-matt

Each second with an undefined array key (not an offset like you) on my installation Nextcloud 23.0.2 img_2022-05-03 170733

phmign avatar May 03 '22 15:05 phmign

Every second is correct - the background job is looping through all contacts with a one second break after each.

I guess the error is the same (offset or array key): It seems to find contacts in the cron-job which then disappear right afterwards in the next call for the actual update.

I spent my evening in trying to reproduce the error:

  • having no contacts: not a problem
  • having only recently contacted contacts: not a problem
  • having recently contacted and address book contacts: not a problem
  • having shared contacts with a different user: not a problem
  • having shared contacts from a different user: not a problem

I am using this dev-setup for my tests.

Any idea, @skjnldsv ?

call-me-matt avatar May 03 '22 20:05 call-me-matt

Do we actually need to search again in https://github.com/nextcloud/contacts/blob/344730d161243d69b24b5f8857949ba474db8934/lib/Service/SocialApiService.php#L184

Can't we just pass the contact we already have from https://github.com/nextcloud/contacts/blob/344730d161243d69b24b5f8857949ba474db8934/lib/Service/SocialApiService.php#L410

I guess we can also just sanitize the process to avoid that undefined offset, that would be a nice start.

skjnldsv avatar May 04 '22 06:05 skjnldsv

Also, last supported version is 22 now, I guess we can enable this: https://github.com/nextcloud/contacts/blob/344730d161243d69b24b5f8857949ba474db8934/lib/Service/SocialApiService.php#L387-L395

skjnldsv avatar May 04 '22 06:05 skjnldsv

Do we actually need to search again

I did not find a better way of retrieving the contact from the UID. What do you propose?

And I guess the problem would persist. There is a contact found in the cron-job which then disappears for the update. Of course, we could simply add a check, but I would like to understand what is happening here before just fighting the symptoms.

call-me-matt avatar May 04 '22 10:05 call-me-matt

image

same here, every second but also an interval of 10 minutes apparently:

image

PHP 8.0.18

Omaha2002 avatar May 06 '22 15:05 Omaha2002

After upgrading to NC24, I'm also affected by this issue. I'm on Ubuntu 20.04 with php7.4. Let me know if I can supply any further information to figure out the root cause of this issue.

Update: After applying https://github.com/nextcloud/contacts/pull/2729 the issue seems to be gone.

XueSheng-GIT avatar May 06 '22 18:05 XueSheng-GIT

Thank you for the update. But let's see if it doesn't come back, because these background updates are triggered once per week and then worked off in chunks (one contact per second for 15 seconds per chunk). So maybe they return in a week...

In the meantime, can you check the social update function is working for you? For example by adding a social network for a contact, then selecting Mastodon for the entry and entering [email protected] as value. Next, click on the avatar image icon and select to update from Mastodon. You should see a green info message a few seconds later. If you reload the page (CTRL+F5), the contact should have the Nextcloud-icon as avatar.

call-me-matt avatar May 08 '22 19:05 call-me-matt

Added social contact and select Mastodon:

Schermafbeelding 2022-05-09 om 07 31 19

Update avatar picture "get from mastodon"

Schermafbeelding 2022-05-09 om 07 38 36 Schermafbeelding 2022-05-09 om 07 39 08

After refresh F5 profile picture stays the same:

Schermafbeelding 2022-05-09 om 07 32 15 error in log: Schermafbeelding 2022-05-09 om 07 35 45

Omaha2002 avatar May 09 '22 05:05 Omaha2002

After refresh F5 profile picture stays the same:

Also with CTRL+F5, to make sure there is no cache?

But anyways, I have the same setup and simply cannot reproduce this error. @skjnldsv any idea what is going on here?

call-me-matt avatar May 09 '22 19:05 call-me-matt

Tried CTRL+F5, emptied cache, restarted browser, to no avail, log throwing this error:

[PHP] Fout: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 1036 at /var/www/nextcloud/apps/contacts/lib/Service/Social/MastodonProvider.php#87

PUT /apps/contacts/api/v1/social/avatar/mastodon/contacts/76f0163c-840f-4096-8e55-32c1d83076a5 from 37.19.195.39 by [email protected] at 2022-05-09T21:30:47+02:00

Omaha2002 avatar May 09 '22 19:05 Omaha2002

The error stopped 2 days ago without any action from me, but the server is not maintained by me (Server of the Zaclys association) Nextcloud_2022-05-10 135536

phmign avatar May 10 '22 12:05 phmign

Oups, finally, the errors had restarted, after a 2 days break Nextcloud-2022-05-11 092250

phmign avatar May 11 '22 07:05 phmign

Are you able to patch stuff? If so, you could try to change lines 183ff to this:

			// search contact in that addressbook, get social data
			$contacts = $addressBook->search($contactId, ['UID'], ['types' => true]);

			if (empty($contacts)) {
				return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
			}

			$contact = $contacts[0];

And see if that helps.

I will open a pr for this too so you can check out that branch if you want.

miaulalala avatar May 11 '22 08:05 miaulalala

Hi @miaulalala and thank you so much for helping out! Concerning your proposal, I am afraid suppressing the error messages is only fighting the symptoms. We need to find out why the update is not working for some users anymore.

call-me-matt avatar May 11 '22 16:05 call-me-matt