Re: [Zope-dev] ConnectionStateError

2011-01-12 Thread Godefroid Chapelle
Le 12/01/11 17:06, Hanno Schlichting a écrit :
> On Wed, Jan 12, 2011 at 2:34 PM, Godefroid Chapelle  
> wrote:
>> I understand that I should look for persistent objects stored in module
>> or class level variables (which imply shared by threads and thus
>> connections). Do not hesitate to tell me if this is a wrong explanation
>> of the potential cause of ConnectionStateError.
>>
>> However, I wonder if some of you could give debugging techniques outside
>> reviewing the code.

Thanks for help from anyone.

Once debugged, I'll blog how I found the bug.

> Do you get the classic: "Shouldn't load state for %s when the
> connection is closed" or one of the "The database connection is
> closed" errors?
>
> In the first case you get the p_oid, which you can load from the
> database to give you some clue on what class it is.

I had no clue that the number in the error message was the p_oid. I 
could have found out by reading the code.

Nevertheless, I propose to make the error message more self-explanatory.

> Typical problems include using plone.memoize decorators on things
> without knowing where exactly the cache is stored or as someone else
> noted registering persistent objects in the global site manager
> instead of the local one. The global one is of course just a module
> global data structure in the end.
>
> Hanno

-- 
Godefroid Chapelle (aka __gotcha) http://bubblenet.be

___
Zope-Dev maillist  -  Zope-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] ConnectionStateError

2011-01-12 Thread Hanno Schlichting
On Wed, Jan 12, 2011 at 2:34 PM, Godefroid Chapelle  wrote:
> I understand that I should look for persistent objects stored in module
> or class level variables (which imply shared by threads and thus
> connections). Do not hesitate to tell me if this is a wrong explanation
> of the potential cause of ConnectionStateError.
>
> However, I wonder if some of you could give debugging techniques outside
> reviewing the code.

Do you get the classic: "Shouldn't load state for %s when the
connection is closed" or one of the "The database connection is
closed" errors?

In the first case you get the p_oid, which you can load from the
database to give you some clue on what class it is.

Typical problems include using plone.memoize decorators on things
without knowing where exactly the cache is stored or as someone else
noted registering persistent objects in the global site manager
instead of the local one. The global one is of course just a module
global data structure in the end.

Hanno
___
Zope-Dev maillist  -  Zope-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] ConnectionStateError

2011-01-12 Thread Dan Fairs
> We have been experiencing some ConnectionStateError in a Zope 2 based 
> application.
> 
> Looking for info on the web makes me almost 100% sure that we have a bug 
> in our application layer.
> 
> I understand that I should look for persistent objects stored in module 
> or class level variables (which imply shared by threads and thus 
> connections). Do not hesitate to tell me if this is a wrong explanation 
> of the potential cause of ConnectionStateError.
> 

I've experienced this error, and that was indeed the cause. IIRC, in the case 
of the app I was dealing with at the time, it had managed to register a 
persistent object as a utility - and so ended up in the situation where the 
application tried to load the object using the wrong database connection.

The moral of the story here is that there are more places than just module 
level globals to look :)

It happened some time ago, so I'm afraid I cannot recall how we debugged it 
(only the amount of facepalming when we did.) I suspect finding out what the 
type of object was turned out to be a good indicator in our case, as it would 
only have been used in a couple of places. 

Cheers,
Dan
--
Dan Fairs | dan.fa...@gmail.com | www.fezconsulting.com


___
Zope-Dev maillist  -  Zope-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] ConnectionStateError

2011-01-12 Thread Marius Gedminas
On Wed, Jan 12, 2011 at 02:34:13PM +0100, Godefroid Chapelle wrote:
> We have been experiencing some ConnectionStateError in a Zope 2 based 
> application.
> 
> Looking for info on the web makes me almost 100% sure that we have a bug 
> in our application layer.
> 
> I understand that I should look for persistent objects stored in module 
> or class level variables (which imply shared by threads and thus 
> connections). Do not hesitate to tell me if this is a wrong explanation 
> of the potential cause of ConnectionStateError.
> 
> However, I wonder if some of you could give debugging techniques outside 
> reviewing the code.

I would be inclined to use pdb, get hold of the offending object, and
then use http://mg.pov.lt/objgraph/ to find which global variable refers
to it.

(It could be a case of "if all you've got is a hammer", since objgraph is
still shiny in my mind.)

> I also wonder what was the reason to deprecate ``zope.thread``.

Because it was folded into the standard library in Python 2.4.
zope.thread.local() became threading.local()

> I see it 
> was used by ``zope.component`` to hold thread-safe siteinfo. Could a too 
> frequent usage of getSite lead to ConnectionStateError ? I think that it 
> is not the case but I prefer to ask.

Unlikely.

Marius Gedminas
-- 
http://pov.lt/ -- Zope 3/BlueBream consulting and development


signature.asc
Description: Digital signature
___
Zope-Dev maillist  -  Zope-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] ConnectionStateError

2011-01-12 Thread Wichert Akkerman
On 1/12/11 14:34 , Godefroid Chapelle wrote:
> I also wonder what was the reason to deprecate ``zope.thread``. I see it
> was used by ``zope.component`` to hold thread-safe siteinfo.

It has been obsoleted by 
http://docs.python.org/library/threading.html#threading.local

Wichert.
___
Zope-Dev maillist  -  Zope-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )