title: What are the possible causes of a ConnectionStateError?
body: <p>I'm having trouble with a <code>ConnectionStateError</code> that happens sometimes on a Plone 4.3.8 site.</p>
  
  <p>I can't find the reason why it happens. I get it in many different situations, I'll post a couple tracebacks to show you what I mean.</p>
  
  <p>Loading a portlet page:</p>
  
  <pre><code>2016-08-01T11:38:15 ERROR Zope.SiteErrorLog 1470044295.40.967961803473 https://mysite.it/home-page/two-columns
  Traceback (innermost last):
    Module ZPublisher.Publish, line 127, in publish
    Module ZPublisher.BaseRequest, line 607, in traverse
    Module Products.PluggableAuthService.PluggableAuthService, line 244, in validate
    Module Products.PluggableAuthService.PluggableAuthService, line 652, in _extractUserIds
    Module Products.WebServerAuth.plugin, line 131, in authenticateCredentials
    Module ZODB.Connection, line 857, in setstate
  ConnectionStateError: Shouldn't load state for 0x184af9 when the connection is closed
  </code></pre>
  
  <p>Loading a random folder:</p>
  
  <pre><code>2016-08-01T13:04:17 ERROR Zope.SiteErrorLog 1470049457.660.586381895694 https://mysite.it/some/path/folder_tabular_view
  Traceback (innermost last):
    Module ZPublisher.Publish, line 138, in publish
    Module ZPublisher.mapply, line 77, in mapply
    Module ZPublisher.Publish, line 48, in call_object
    Module Shared.DC.Scripts.Bindings, line 322, in __call__
    Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
    Module Products.CMFCore.FSPageTemplate, line 237, in _exec
    Module Products.CMFCore.FSPageTemplate, line 177, in pt_render
    Module Products.PageTemplates.PageTemplate, line 87, in pt_render
    Module zope.pagetemplate.pagetemplate, line 132, in pt_render
    Module five.pt.engine, line 93, in __call__
    Module z3c.pt.pagetemplate, line 149, in render
    Module chameleon.zpt.template, line 261, in render
    Module chameleon.template, line 191, in render
    Module chameleon.template, line 171, in render
    Module 3d823c0177a7023e7fe9a133289da7b0.py, line 853, in render
    Module 153d4bce30f6569f92b3bf03cb6d6485.py, line 1060, in render_master
    Module z3c.pt.expressions, line 58, in render_content_provider
    Module zope.viewlet.manager, line 112, in update
    Module zope.viewlet.manager, line 118, in _updateViewlets
    Module plone.app.layout.links.viewlets, line 122, in update
    Module Products.CMFPlone.browser.syndication.utils, line 47, in context_enabled
    Module zope.component.hookable, line 33, in __call__
    Module zope.component.hooks, line 104, in adapter_hook
    Module Products.CMFPlone.browser.syndication.settings, line 23, in __init__
    Module zope.annotation.attribute, line 44, in get
    Module ZODB.Connection, line 857, in setstate
  ConnectionStateError: Shouldn't load state for 0x05f568 when the connection is closed
  
   - Expression: "provider:plone.htmlhead.links"
   - Filename:   ... me/skins/my_plonetheme_custom_templates/main_template.pt
   - Location:   (line 32: col 37)
   - Source:     ... replace="structure provider:plone.htmlhead.links" /&gt;
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   - Arguments:  repeat: {...} (0)
                 template: &lt;ImplicitAcquisitionWrapper folder_tabular_view at 0x7fb4e901b820&gt;
                 modules: &lt;instance - at 0x7fb509ba5878&gt;
                 here: &lt;ImplicitAcquisitionWrapper i-commisione-consiliare at 0x7fb4e901ba50&gt;
                 user: &lt;ImplicitAcquisitionWrapper - at 0x7fb4e901baf0&gt;
                 nothing: &lt;NoneType - at 0x937be0&gt;
                 container: &lt;ImplicitAcquisitionWrapper i-commisione-consiliare at 0x7fb4e901ba50&gt;
                 default: &lt;object - at 0x7fb510fbc520&gt;
                 request: &lt;instance - at 0x7fb4ddaafe60&gt;
                 wrapped_repeat: &lt;SafeMapping - at 0x7fb4df604520&gt;
                 traverse_subpath: &lt;list - at 0x7fb4dfba61b8&gt;
                 loop: {...} (0)
                 context: &lt;ImplicitAcquisitionWrapper i-commisione-consiliare at 0x7fb4e901ba50&gt;
                 translate: &lt;function translate at 0x7fb4de933848&gt;
                 root: &lt;ImplicitAcquisitionWrapper Zope at 0x7fb4e8b5a960&gt;
                 options: {...} (1)
                 target_language: &lt;NoneType - at 0x937be0&gt;
  </code></pre>
  
  <p>Loading a viewlet:</p>
  
  <pre><code>2016-08-02T22:53:57 ERROR plone.app.viewletmanager rendering of plone.belowcontenttitle in plone.belowcontenttitle.documentbyline fails: Shouldn't load state for 0x1e3183 when the connection is closed
  
   - Expression: "context/Rights"
   - Filename:   ... 4-py2.7.egg/plone/app/layout/viewlets/document_byline.pt
   - Location:   (line 79: col 33)
   - Source:     ... rights tal:define="rights context/Rights"
                                               ^^^^^^^^^^^^^^
   - Arguments:  repeat: {...} (0)
                 template: &lt;ViewPageTemplateFile - at 0x7fb501617990&gt;
                 views: &lt;ViewMapper - at 0x7fb4deb88410&gt;
                 modules: &lt;instance - at 0x7fb509ba5878&gt;
                 args: &lt;tuple - at 0x7fb51109e050&gt;
                 here: &lt;ImplicitAcquisitionWrapper notizie at 0x7fb4ea918aa0&gt;
                 user: &lt;ImplicitAcquisitionWrapper - at 0x7fb4e8734960&gt;
                 nothing: &lt;NoneType - at 0x937be0&gt;
                 container: &lt;ImplicitAcquisitionWrapper notizie at 0x7fb4ea918aa0&gt;
                 request: &lt;instance - at 0x7fb4f13d37e8&gt;
                 wrapped_repeat: &lt;SafeMapping - at 0x7fb4d7edd7e0&gt;
                 traverse_subpath: &lt;list - at 0x7fb4de297dd0&gt;
                 default: &lt;object - at 0x7fb510fbc520&gt;
                 loop: {...} (0)
                 context: &lt;ImplicitAcquisitionWrapper notizie at 0x7fb4ea918aa0&gt;
                 view: &lt;DocumentBylineViewlet plone.belowcontenttitle.documentbyline at 0x7fb4deb888d0&gt;
                 translate: &lt;function translate at 0x7fb4dc1ce320&gt;
                 root: &lt;ImplicitAcquisitionWrapper Zope at 0x7fb4dfcd4370&gt;
                 options: {...} (0)
                 target_language: &lt;NoneType - at 0x937be0&gt;
  Traceback (most recent call last):
    File "/opt/cache/buildout/eggs/plone.app.viewletmanager-2.0.9-py2.7.egg/plone/app/viewletmanager/manager.py", line 110, in render
      html.append(viewlet.render())
    File "/opt/cache/buildout/eggs/plone.app.layout-2.3.14-py2.7.egg/plone/app/layout/viewlets/common.py", line 50, in render
      return self.index()
    File "/opt/cache/buildout/eggs/Zope2-2.13.23-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 125, in __call__
      return self.im_func(im_self, *args, **kw)
    File "/opt/cache/buildout/eggs/Zope2-2.13.23-py2.7.egg/Products/Five/browser/pagetemplatefile.py", line 59, in __call__
      sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
    File "/opt/cache/buildout/eggs/zope.pagetemplate-3.6.3-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 132, in pt_render
      strictinsert=0, sourceAnnotations=sourceAnnotations
    File "/opt/cache/buildout/eggs/five.pt-2.2.3-py2.7.egg/five/pt/engine.py", line 93, in __call__
      return self.template.render(**kwargs)
    File "/opt/cache/buildout/eggs/z3c.pt-2.2.3-py2.7.egg/z3c/pt/pagetemplate.py", line 149, in render
      return base_renderer(**context)
    File "/opt/cache/buildout/eggs/Chameleon-2.24-py2.7.egg/chameleon/zpt/template.py", line 261, in render
      return super(PageTemplate, self).render(**vars)
    File "/opt/cache/buildout/eggs/Chameleon-2.24-py2.7.egg/chameleon/template.py", line 191, in render
      raise_with_traceback(exc, tb)
    File "/opt/cache/buildout/eggs/Chameleon-2.24-py2.7.egg/chameleon/template.py", line 171, in render
      self._render(stream, econtext, rcontext)
    File "c3f6907c0e1b52a047b37fee3042155a.py", line 699, in render
    File "/opt/cache/buildout/eggs/five.pt-2.2.3-py2.7.egg/five/pt/expressions.py", line 161, in __call__
      return base()
    File "/opt/cache/buildout/eggs/Products.Archetypes-1.9.10-py2.7.egg/Products/Archetypes/ClassGen.py", line 56, in generatedAccessor
      return schema[name].get(self, **kw)
    File "/opt/cache/buildout/eggs/wicked-1.1.12-py2.7.egg/wicked/fieldevent/__init__.py", line 29, in render
      notify(renderer)
    File "/opt/cache/buildout/eggs/zope.event-3.5.2-py2.7.egg/zope/event/__init__.py", line 31, in notify
      subscriber(event)
    File "/opt/cache/buildout/eggs/zope.component-3.9.5-py2.7.egg/zope/component/event.py", line 24, in dispatch
      zope.component.subscribers(event, None)
    File "/opt/cache/buildout/eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 136, in subscribers
      return sitemanager.subscribers(objects, interface)
    File "/opt/cache/buildout/eggs/zope.component-3.9.5-py2.7.egg/zope/component/registry.py", line 321, in subscribers
      return self.adapters.subscribers(objects, provided)
    File "/opt/cache/buildout/eggs/zope.interface-3.6.7-py2.7-linux-x86_64.egg/zope/interface/adapter.py", line 585, in subscribers
      subscription(*objects)
    File "/opt/cache/buildout/eggs/wicked-1.1.12-py2.7.egg/wicked/fieldevent/__init__.py", line 16, in notifyFieldEvent
      event.value = getMultiAdapter((field, event), IFieldValue)
    File "/opt/cache/buildout/eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 107, in getMultiAdapter
      adapter = queryMultiAdapter(objects, interface, name, context=context)
    File "/opt/cache/buildout/eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 120, in queryMultiAdapter
      return sitemanager.queryMultiAdapter(objects, interface, name, default)
    File "/opt/cache/buildout/eggs/zope.component-3.9.5-py2.7.egg/zope/component/registry.py", line 238, in queryMultiAdapter
      objects, interface, name, default)
    File "/opt/cache/buildout/eggs/zope.interface-3.6.7-py2.7-linux-x86_64.egg/zope/interface/adapter.py", line 532, in queryMultiAdapter
      result = factory(*objects)
    File "/opt/cache/buildout/eggs/wicked-1.1.12-py2.7.egg/wicked/fieldevent/meta.py", line 78, in field_value
      return _get(field, event.instance, **event.kwargs)
    File "/opt/cache/buildout/eggs/Products.Archetypes-1.9.10-py2.7.egg/Products/Archetypes/Field.py", line 1502, in get
      if not shasattr(value, 'transform'):  # oldBaseUnits have no transform
    File "/opt/cache/buildout/eggs/Products.Archetypes-1.9.10-py2.7.egg/Products/Archetypes/utils.py", line 734, in shasattr
      return getattr(obj, attr, _marker) is not _marker
    File "/opt/cache/buildout/eggs/ZODB3-3.10.5-py2.7-linux-x86_64.egg/ZODB/Connection.py", line 857, in setstate
      raise ConnectionStateError(msg)
  ConnectionStateError: Shouldn't load state for 0x1e3183 when the connection is closed
  
   - Expression: "context/Rights"
   - Filename:   ... 4-py2.7.egg/plone/app/layout/viewlets/document_byline.pt
   - Location:   (line 79: col 33)
   - Source:     ... rights tal:define="rights context/Rights"
                                               ^^^^^^^^^^^^^^
   - Arguments:  repeat: {...} (0)
                 template: &lt;ViewPageTemplateFile - at 0x7fb501617990&gt;
                 views: &lt;ViewMapper - at 0x7fb4deb88410&gt;
                 modules: &lt;instance - at 0x7fb509ba5878&gt;
                 args: &lt;tuple - at 0x7fb51109e050&gt;
                 here: &lt;ImplicitAcquisitionWrapper notizie at 0x7fb4ea918aa0&gt;
                 user: &lt;ImplicitAcquisitionWrapper - at 0x7fb4e8734960&gt;
                 nothing: &lt;NoneType - at 0x937be0&gt;
                 container: &lt;ImplicitAcquisitionWrapper notizie at 0x7fb4ea918aa0&gt;
                 request: &lt;instance - at 0x7fb4f13d37e8&gt;
                 wrapped_repeat: &lt;SafeMapping - at 0x7fb4d7edd7e0&gt;
                 traverse_subpath: &lt;list - at 0x7fb4de297dd0&gt;
                 default: &lt;object - at 0x7fb510fbc520&gt;
                 loop: {...} (0)
                 context: &lt;ImplicitAcquisitionWrapper notizie at 0x7fb4ea918aa0&gt;
                 view: &lt;DocumentBylineViewlet plone.belowcontenttitle.documentbyline at 0x7fb4deb888d0&gt;
                 translate: &lt;function translate at 0x7fb4dc1ce320&gt;
                 root: &lt;ImplicitAcquisitionWrapper Zope at 0x7fb4dfcd4370&gt;
                 options: {...} (0)
                 target_language: &lt;NoneType - at 0x937be0&gt;
  </code></pre>
  
  <p>I could go with many different examples.
  I can't seem to find the reason of this, I'm probably missing some information on what can cause the problem.</p>
  
  <p>I will give any extra information needed, feel free to ask :)
  Thanks! </p>