passbolt/passbolt_api · error · InternalErrorException

Could not save the metadata session keys, please try again…

Error message

Could not save the metadata session keys, please try again later.

What it means

MetadataTypesSettingsAssertService wraps unexpected persistence exceptions. After the metadata session key entity fails to save for a reason other than validation, the service converts the underlying exception into a CakePHP InternalErrorException (HTTP 500) telling the client to retry later. It signals a server-side problem (DB, key server, crypto) rather than bad client input.

Solutions

  1. Check database connectivity and the app error logs for the wrapped original exception (chained as previous).
  2. Retry the request after a short delay — the message explicitly asks the client to try again later.
  3. Verify DB credentials/privileges for the passbolt user and that the metadata_session_keys table exists (run migrations).
  4. Check for lock waits / long-running transactions on the session key table and reduce concurrent rotations.

Example fix

// before
$sessionKey = $this->MetadataSessionKeys->save($entity);
// after
try {
    $this->MetadataSessionKeys->getConnection()->begin();
    $sessionKey = $this->MetadataSessionKeys->save($entity);
    $this->MetadataSessionKeys->getConnection()->commit();
} catch (\Exception $e) {
    $this->MetadataSessionKeys->getConnection()->rollback();
    throw new InternalErrorException(__('Could not save the metadata session keys, please try again later.'), null, $e);
}
Defensive patterns

Strategy: retry

Validate before calling

// check DB reachable before calling the API
try {
    \Cake\Datasource\ConnectionManager::get('default')->query('SELECT 1');
} catch (\Exception $e) { /* abort: database unavailable */ }

Try / catch

try {
    $service->update($user, $data);
} catch (\Cake\Http\Exception\InternalErrorException $e) {
    // retry with backoff; inspect $e->getPrevious() for root cause
    retry(fn() => $service->update($user, $data), attempts: 3, backoffMs: 500);
}

Prevention

When it happens

Trigger: Calling PUT/POST on the metadata session-key update endpoint (MetadataSessionKeyUpdateService::update) when Table::save() throws a non-validation exception, e.g. database connectivity loss, constraint violation not surfaced as entity errors, or a broken transaction.

Common situations: Database down or restarted mid-request; DB user lacking INSERT/UPDATE privileges on session_keys table; MySQL lock timeout under concurrent session-key rotations; Postgres/MySQL dialect issue after a migration.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/ac848a54e1a34596. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltCe/Metadata/src/Service/MetadataSessionKeyUpdateService.php:105

        $metadataSessionKey = $metadataSessionKeysTable->patchEntity(
            $metadataSessionKey,
            ['data' => $data['data']],
            ['accessibleFields' => ['data' => true]]
        );

        try {
            /** @var \Passbolt\Metadata\Model\Entity\MetadataSessionKey $updatedEntity */
            $updatedEntity = $metadataSessionKeysTable->saveOrFail($metadataSessionKey);
        } catch (PersistenceFailedException $exception) { // @phpstan-ignore-line
            // 400 openpgp data does not validate, for example it's not for the current user
            throw new CustomValidationException(
                __('The metadata session key could not be saved.'),
                $exception->getEntity()->getErrors()
            );
        } catch (Exception $exception) {
            // 500 entry could not be deleted because of some internal error
            throw new InternalErrorException(
                __('Could not save the metadata session keys, please try again later.'),
                null,
                $exception
            );
        }

        return $updatedEntity;
    }
}

View on GitHub (pinned to 31c1bbc10f)