Problem/Motivation
There is still the static SessionManager::$enabled property which does not need to be static anymore after #2272987: Do not persist session manager landed. Also there is an implicit cyclic dependency between SessionManager and SessionHandler. After #2342593: Remove mixed SSL support from core landed, this dependency now can be resolved by introducing WriteCheckSessionHandler.
Proposed resolution
In the spirit of Symfonys WriteCheckSessionHandler, replace the $enabled property with a WriteBarrierSessionHandler wrapping the real session save handler.
Remaining tasks
Review.
User interface changes
None.
API changes
None.
Beta phase evaluation
| Issue category | Something between Bug and Task, circular dependency between SessionManager and SessionHandler might qualify as a design defect. |
|---|---|
| Issue priority | Major because this helps removing complexity from SessionHandler and SessionManager and it introduces unit-tests for a mechanism which was not testable before in an easy way. (brittleness--). |
| Disruption | No disruptive changes (no API change) |
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | interdiff.txt | 3.05 KB | almaudoh |
| #36 | 2338727-readonly_session_handler-36.patch | 16.06 KB | almaudoh |
| #33 | interdiff.txt | 8.98 KB | almaudoh |
| #33 | 2338727-readonly_session_handler-33.patch | 15.66 KB | almaudoh |
| #13 | interdiff.txt | 2.48 KB | znerol |
Comments
Comment #1
znerol commentedComment #2
znerol commentedComment #4
znerol commentedFix double-return in
[en|dis]able()and usage of wrong save-handler in__construct().Comment #5
dawehnerI wonder whether we could add an optional dependency already, just to be clear that we actually want to get in the dependency from outside?
Missing empty line.
I really don't like the fact that we introduce privates here.
Comment #6
znerol commentedRerolled, and fixed code style issues. Ultimately
enable(),disable()andisEnabled()should be removed fromSessionManagerentirely. This can be done as soon as all database queries are eliminated from it. Therefore let's postpone this issue until that happens.Comment #7
znerol commentedComment #8
cosmicdreams commentedIs there an issue where the queries are being eliminated?
Comment #9
znerol commentedMost likely #2228393: Decouple session from cookie based user authentication, but this will become much less complex if #2342593: Remove mixed SSL support from core lands.
Comment #10
znerol commented#2342593: Remove mixed SSL support from core is in, now this patch finally makes it possible to break the (hidden) circular dependency between session handler and session manager.
Comment #11
znerol commentedRising the priority to major because this helps removing complexity from
SessionHandlerandSessionManagerand it introduces unit-tests for a mechanism which was not testable before in an easy way. (brittleness--).Also this will help us to introduce #2372389: Expose session handler in container with proper constructor injection instead of the setter-injection implemented there as a temporary workaround.
Comment #12
joelpittet@znerol this looks great in terms of brittleness removal! I've added the beta evaluation table to the IS and added your note to move to Major into it, if you can fill out any of the other commented out rows that could help.
Comment #13
znerol commentedAdd
WriteBarrierInterface. A service implementing this interface should be consumed byAccountSwitcherinstead of the session manager as soon as theWriteBarrierSessionHandlercan be exposed as a container service (#2338727).Comment #15
znerol commentedComment #17
znerol commentedComment #21
znerol commentedComment #22
dawehnerAs said on IRC, I really don't get why we need this additional layer of abstraction. Why can't we just make SessionManager::$enabled a normal property and accept that a SessionHandler
needs the SessionManager ? Its a dependency we are aware of, and solve (which we do already).
Comment #23
cpj commentedI see what the code does, but I'm also unclear what problem we're trying to solve here. How can we decide if this is needed or not ?
Comment #24
znerol commentedFrom the IS:
We should work towards restricting the responsibility of
SessionHandlerto accessing storage exclusively such that contrib/custom handlers (memcache, redis, ...) can be implemented easily and (as a result) more safely.At the moment if anyone intends to replace session storage, she also needs to swap out the
SessionManagerbecause of the close coupling. This issue does not completely solve the problem but is one important step into the direction of decouplingSessionHandler(storage) from theSessionManager(logic).Comment #25
cpj commentedThanks @znerol - that makes sense. I've reviewed the code and have tested the code in our environment. I've stepped through the code in my IDE's debugger and it all works as expected. However, I haven't tested this as part of an environment that swaps out the
SessionHandlerbut I can see that the tests go some way to simulate this. Therefore if there are no objections, I'm going to mark this as "Reviewed & tested by the community" (= me).Comment #26
cpj commentedComment #27
alexpottThe name of the class - barrier seems strange. Also comment is longer than 80 chars. How about WriteSafeSessionHandler?
Comment #28
cpj commentedThe Interface defined functions only say that the Class allows you to enable/disable writing and check the status, so it doesn't really define a "Safe" session handler. So how about WriteCheckSessionHandler ?
Comment #29
znerol commentedSymfony already provides a
WriteCheckSessionHandler(and we are even using it). How aboutReadOnlySessionHandler?Comment #30
almaudoh commented+1.
Comment #31
cpj commented+1 from me too...
Comment #32
almaudoh commented@znerol, @cpj: now that I look at the patch closely, I don't think
ReadOnlySessionHandleris a very good name, because there is the option in this class to make the session writable (which implies that it is not read only).So thinking through, @alexpott's
WriteSafeSessionHandleractually sounds most appropriate, or maybeSafeWriteSessionHandler. If we're going with ReadOnlySessionHandler, then we have to get rid ofsetSessionWritable()andisSessionWritable()Comment #33
almaudoh commentedWe can't get rid of
setSessionWritable()/isSessionWritable(), so...here's the rename.Comment #34
cpj commented@almaudoh - OK, I agree. Either are fine by me but SafeWrite*** seems slightly better to me than WriteSafe***
Comment #35
cpj commentedIsn't this now a WriteSafeSessionHandlerInterface ?
Comment #36
almaudoh commentedThanks @cpj and also some minor clean ups.
Comment #37
almaudoh commentedComment #38
cpj commentedLooks great to me so I'm gonna change this to RTBC (again...)
Comment #39
cpj commentedComment #40
alexpottCommitted 6faa686 and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation to the issue summary.
Comment #41
almaudoh commentedLooks like it wasn't committed. Can't find it on cgit.drupalcode.org or my local git clone.
Comment #43
alexpottComment #44
almaudoh commentedThanks @alexpott. Now on to #2372389: Expose session handler in container which was blocked on this issue.