Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(session): Log critical conditions where sessions might be lost #40878

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/private/Session/Internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Token\IProvider;
use OCP\Session\Exceptions\SessionNotAvailableException;
use function headers_sent;
use function OCP\Log\logger;

/**
* Class Internal
Expand Down Expand Up @@ -138,6 +140,14 @@ public function regenerateId(bool $deleteOldSession = true, bool $updateToken =
}
}

if (headers_sent()) {
logger('core')->critical('Regenerating session ID but headers have been sent. This session will be lost.', [
'deleteOldSession' => $deleteOldSession,
]);
} elseif ($deleteOldSession) {
logger('core')->warning('Calling session_regenerate_id with delete_old_session=true can lead to lost sessions');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be lowered to debug. this is called a lot

}

try {
@session_regenerate_id($deleteOldSession);
} catch (\Error $e) {
Expand Down Expand Up @@ -222,6 +232,12 @@ private function startSession(bool $silence = false, bool $readAndClose = true)
if (\OC::hasSessionRelaxedExpiry()) {
$sessionParams['read_and_close'] = $readAndClose;
}
if (headers_sent()) {
logger('core')->critical('Starting session but headers have been sent. This session will be lost.', [
'silence' => $silence,
'readAndClose' => $readAndClose,
]);
}
$this->invoke('session_start', [$sessionParams], $silence);
}
}
Loading