6.0.0-git
2019-03-18

[#9282] Using SQL sessionhandler and SQL cache causes infinite recursion
Summary Using SQL sessionhandler and SQL cache causes infinite recursion
Queue Horde Base
Queue Version Git master
Type Bug
State Resolved
Priority 1. Low
Owners Horde Developers (at)
Requester bklang (at) horde (dot) org
Created 2010-10-02 (3089 days ago)
Due
Updated 2011-01-24 (2975 days ago)
Assigned 2010-10-05 (3086 days ago)
Resolved 2011-01-24 (2975 days ago)
Milestone 4
Patch No

History
2011-01-24 03:36:23 Chuck Hagenbuch Comment #8
State ⇒ Resolved
Reply to this comment
Ultimately, I way overthought this. Works for me now.
2011-01-24 03:34:40 Git Commit Comment #7 Reply to this comment
Changes have been made in Git for this ticket:

Bug #9282: When creating Horde_Db objects, register them with a child 
injector before creating any dependencies that could in turn want a 
Horde_Db dependency.

http://git.horde.org/horde-git/-/commit/fa4fbb47bf73abd59ae6d690fb25594576acfe16
2011-01-24 01:34:35 Chuck Hagenbuch Comment #6 Reply to this comment
I don't think that'd work ultimately either. Horde_Db logging queries 
when the logger is configured to log using Horde_Db is always going to 
create an infinite loop, even if we get past the object construction 
phase.
2011-01-18 05:57:17 Michael Slusarz Comment #5 Reply to this comment
What about the idea I floated on dev@ about a 'queued' Logger 
instance?  On dev@ I was discussing the use of a queued logger during 
the time before the log object itself was available (e.g. before the 
Horde config could be parsed).  But a queued logger could likewise be 
used in this instance - log requests to the logger are queued until 
the logger can determine that the backend (the DB object) is fully 
initialized.
2011-01-16 04:26:45 Chuck Hagenbuch Comment #4 Reply to this comment
Spent some time on this tonight and I'm leaning toward the problem 
being that logger and cache shouldn't be getting a full-fledged 
Horde_Db_Adapter, or that Horde_Db_Adapter shouldn't include logging 
and caching, but a higher-level object should. From the comments at 
http://misko.hevery.com/2008/08/01/circular-dependency-in-constructors-and-dependency-injection/:

@Peter,

here is how I would attack you problem.

class Database() implements DB;
class Logger(Database db);
class LoggingDatabase(Logger log, Database db) implements DB;

DB rawDatabase = new Database();
Logger log = new Logger(rowDatabase);
DB dbForTheRestoOfApplication = new LoggingDatabase(log, rowDatabase);

There you go. LoggingDatabase logs the commands as they go by and than 
delegate it on a class of the same interface. This is know as chain of 
responsibility and it is my favorite design pattern.

... so, that seems clean, but will take a little work.
2010-10-05 17:34:48 Michael Slusarz Comment #3 Reply to this comment
Never mind... the cyclic dependency is that the SessionHandler driver 
is using Db storage -> the Db is creating a cache object to store 
things like Db schema info -> the cache is stored in the Db itself.

Looks like we need some way to pass the cache object to the Db before 
it is instantiated.  I'm guessing this might be a place to use 
injector/factories(?)
2010-10-05 17:05:08 Michael Slusarz Comment #2 Reply to this comment
I think this has come up before (possibly within Horde_Db itself).   
The solution is to add the logger to the object after creating it via 
a setLogger() call instead of in the constructor.
2010-10-05 15:43:08 Michael Rubinsky Assigned to Horde DevelopersHorde Developers
State ⇒ Assigned
Milestone ⇒ 4
 
2010-10-02 20:27:05 Ben Klang Comment #1
Type ⇒ Bug
State ⇒ Unconfirmed
Priority ⇒ 1. Low
Summary ⇒ Using SQL sessionhandler and SQL cache causes infinite recursion
Queue ⇒ Horde Base
Milestone ⇒
Patch ⇒ No
Reply to this comment
Partial backtrace:

1        0.0016        795432        {main}( )        ../config.php:0
2        0.1231        2465768        Horde_Registry::appInit( )        ../config.php:12
3        0.1231        2468832        Horde_Registry->__construct( )        ../Registry.php:207
4        0.1495        3447712        Horde_Registry->setupSessionHandler( )        ../Registry.php:415
5        0.1496        3449360        Horde_Injector->createInstance( )        ../Registry.php:1657
6        0.1507        3488920        Horde_Core_Binder_SessionHandler->create( 
)        ../Injector.php:261
7        0.1515        3544704        Horde_Core_Factory_Db->getDb( )        ../SessionHandler.php:23
8        0.1516        3546296        Horde_Core_Factory_Db->getDb( )        ../Db.php:86
9        0.1516        3547576        Horde_Core_Factory_Db->_createDb( )        ../Db.php:91
10        0.1586        4322088        Horde_Injector->getInstance( )        ../Db.php:155
11        0.1586        4322088        Horde_Injector->createInstance( )        ../Injector.php:297
12        0.1595        4329016        Horde_Core_Binder_Cache->create( )        ../Injector.php:261
13        0.1603        4362464        Horde_Core_Factory_Cache->getCache( )        ../Cache.php:11
14        0.1734        4603584        Horde_Core_Factory_Db->getDb( )        ../Cache.php:94
15        0.1735        4605000        Horde_Core_Factory_Db->getDb( )        ../Db.php:86
16        0.1735        4606280        Horde_Core_Factory_Db->_createDb( )        ../Db.php:91
17        0.1749        4633496        Horde_Injector->getInstance( )        ../Db.php:155
18        0.1749        4633496        Horde_Injector->createInstance( )        ../Injector.php:297
19        0.1750        4633544        Horde_Core_Binder_Cache->create( )        ../Injector.php:261
20        0.1750        4634056        Horde_Core_Factory_Cache->getCache( )        ../Cache.php:11
21        0.1750        4635968        Horde_Core_Factory_Db->getDb( )        ../Cache.php:94
22        0.1751        4637384        Horde_Core_Factory_Db->getDb( )        ../Db.php:86
23        0.1751        4638664        Horde_Core_Factory_Db->_createDb( )

Saved Queries