zope.interface icon indicating copy to clipboard operation
zope.interface copied to clipboard

How to handle ConnectionStateErrors when looking up for adapters and closed connections

Open ale-rt opened this issue 1 year ago • 4 comments

When we look up for adapters:

https://github.com/zopefoundation/zope.interface/blob/405017fef489ff9d517d0e86e6cb0e6a14fb9bd6/src/zope/interface/adapter.py#L818

We might have:

  1. a closed connection
  2. and a persistent adapter registry

See:

(Pdb++) self._registry.ro[0]
<zope.component.persistentregistry.PersistentAdapterRegistry object at 0x7fcbd097b3f0 oid 0x969d3f9388a51b2 in <Connection at 7fcbd22f1010>>
(Pdb++) self._registry.ro[0]._subscribers.__class__
<class 'persistent.list.PersistentList'>

This causes the _uncached_subscriptions to raise a ConnectionStateError.

The issue happens since zope.component 5, before the persistent adapter registry was storing a list, see:

  • https://github.com/zopefoundation/zope.component/pull/53

What would be the best way to handle this issue? Adding a:

try:
    ...
except ConnectionStateError:
    continue

might be an idea?

Originally discovered while debugging:

https://github.com/plone/plone.testing/issues/83

What version of Python and Zope/Addons I am using:

Tested on Plone 6 with:

  • Python 3.8 and Python 3.11
  • zope.interface 6.0
  • zope.component 5.1.0

ale-rt avatar Jun 08 '23 10:06 ale-rt