Problem/Motivation

Part of #2959269: [meta] Core should not trigger deprecated code except in tests and during updates.

This is another one that seems to be reported on every request, so also setting the priority to major.

Need to see what exactly we need to do, just removing the proxy class resolves it, wondering if we have test coverage for that lazy writing, I hope so...

Proposed resolution

  • Merge functionality into \Drupal\Core\Session\WriteSafeSessionHandler / session_handler.write_safe service
  • Remove session_handler.write_check service
  • Open follow-up to use built-in PHP functionality - [#3001185]

Remaining tasks

User interface changes

None

API changes

session_handler.write_check service is removed

Data model changes

None

Release notes snippet

The service session_handler.write_check has been removed from core.services.yml. In the unlikely event that this service is being swapped out the functionality has been moved to \Drupal\Core\Session\WriteSafeSessionHandler - the session_handler.write_safe service.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir created an issue. See original summary.

Berdir’s picture

Berdir’s picture

Status: Needs review » Needs work

The last submitted patch, 2: remove-write-check-session-handler-2961861-2.patch, failed testing. View results

Berdir’s picture

Hm, the alternative mentioned in the message doesn't make sense for us. We specifically don't want to do any updates, also not the timestamp.

I guess we should just copy the class to our namespace and keep using it? Or put the relevant logic in \Drupal\Core\Session\SessionHandler?

alexpott’s picture

Status: Needs work » Needs review
FileSize
4.2 KB
+++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
@@ -182,7 +182,6 @@ public static function getSkippedDeprecations() {
       'The "session_handler.write_check" service relies on the deprecated "Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler" class. It should either be deprecated or its implementation upgraded.',

Should also be able to remove this deprecation here too.

I think it is reasonable to merge this functionality into \Drupal\Core\Session\WriteSafeSessionHandler

Berdir’s picture

Yeah, was thinking to do the same, makes sense and is pretty simple then. Looks good to me.

alexpott’s picture

+++ b/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php
@@ -19,6 +19,13 @@ class WriteSafeSessionHandler implements \SessionHandlerInterface, WriteSafeSess
+  private $readSessions;

I kept this as private because it makes sense that this info should never leak out of this object. It's private in Symfony's implementation.

alexpott’s picture

I think once we support only PHP 7.0 then we can probably remove this completely and use http://php.net/manual/en/session.configuration.php#ini.session.lazy-write

Berdir’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php
@@ -19,6 +19,13 @@ class WriteSafeSessionHandler implements \SessionHandlerInterface, WriteSafeSess
+   * The read sessions.
+   *
+   * @var array sessionId => session
+   */
+  private $readSessions;

I think the "sessionId => session" part violates our coding standard?

Mile23’s picture

Issue tags: +Needs followup

Needs follow-up for the work in #9, with a @todo.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Pasqualle’s picture

As I see we are free to use PHP 7 here. I am not sure if I understand the issue, but I hope it helps.

alexpott’s picture

Status: Needs work » Needs review
FileSize
564 bytes
3.6 KB

Fixed #11. I'm not sure about adding an @todo. There is plenty of session changes we can make once we are PHP 7 only. Happy to open an issue though. Opened #3001180: Use session.lazy-write once Drupal 8 only supports PHP 7

alexpott’s picture

+++ b/core/core.services.yml
@@ -1545,10 +1545,6 @@ services:
-  session_handler.write_check:
-    class: Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler
-    tags:
-      - { name: session_handler_proxy, priority: 100 }

I think removing this service in a minor is okay because it is like an event subscriber and not really meant to be overridden. Should have a CR though.

alexpott’s picture

Pasqualle’s picture

once we are PHP 7 only

I do not understand, Drupal 8.7 is PHP 7 only. And this issue should not be backported to 8.6.
So why not solve it with PHP 7?

alexpott’s picture

@Pasqualle because there is an idea of maintaining PHP 5.6 support in 8.7.x unless we really can't.

larowlan’s picture

+++ b/core/core.services.yml
@@ -1545,10 +1545,6 @@ services:
-  session_handler.write_check:

according to http://grep.xnddx.ru/search?text=session_handler.write_check the only uses of this are in the IDE helper project, which is a meta project

but I will defer to release manager on this, in an ideal world, we'd mark it private in one minor and remove in another, but I don't think it warrants that effort - a change record and release notes snippet will suffice in my opinion

Tagging for release manager review, and we need a release notes snippet here

catch’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs release manager review

Agreed this is fine in a minor with a change record, thanks for opening the follow-up issue.

Looks RTBC to me too.

The last submitted patch, 6: 2961861-6.patch, failed testing. View results

andypost’s picture

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

We still need a release notes snippet here, then can go back to RTBC

alexpott’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs followup, -Needs release note

Updated issue summary.

alexpott’s picture

Issue summary: View changes
larowlan’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php
@@ -64,14 +72,20 @@ public function open($save_path, $session_id) {
+    // Only write the session when it has been modified.
+    if (isset($this->readSessions[$session_id]) && $this->readSessions[$session_id] === $session_data) {
+      return TRUE;
+    }
+    elseif ($this->isSessionWritable()) {
       return $this->wrappedSessionHandler->write($session_id, $session_data);
     }

because we return early, we don't need the elseif and else here

alexpott’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
735 bytes
3.61 KB

Done. Considering there's no real change straight back to RTBC.

  • larowlan committed 9498875 on 8.7.x
    Issue #2961861 by alexpott, Berdir: Remove usage of...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +8.7.0 release notes

Committed 9498875 and pushed to 8.7.x. Thanks!

Published change record

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.