Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of sockets not closed during testing #636

Closed
gforcada opened this issue Nov 12, 2018 · 2 comments · Fixed by #651
Closed

Lots of sockets not closed during testing #636

gforcada opened this issue Nov 12, 2018 · 2 comments · Fixed by #651

Comments

@gforcada
Copy link
Sponsor Contributor

Have a look at any 3.6/3.7 jenkins jobs, i.e. https://jenkins.plone.org/job/plone-5.2-python-3.6/ or https://jenkins.plone.org/job/plone-5.2-python-3.7/ and you will see that after this line:

Set up plone.restapi.testing.PloneRestApiDXLayer:Functional in 0.000 seconds.

There are lots, literally lots, of:

zope/testrunner/runner.py:386: ResourceWarning: unclosed <socket.socket fd=8, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 51612), raddr=('127.0.0.1', 50139)>
  test.__dict__.clear()

On the up side, it feels like all of them come from the very same place, so with one stone all of them might be gone 👍

@davisagli
Copy link
Sponsor Member

My guess is something about the StopableWSGIServer started by plone.testing (which is a thin wrapper around waitress).

@mauritsvanrees
Copy link
Sponsor Member

So this happens during the call to test.__dict__.clear(). In my case it looks like this:

(Pdb) pp test.__dict__
{'_cleanups': [],
 '_outcome': None,
 '_subtest': None,
 '_testMethodDoc': None,
 '_testMethodName': 'test_documentation_users_add',
 '_type_equality_funcs': {<class 'list'>: 'assertListEqual',
                          <class 'dict'>: 'assertDictEqual',
                          <class 'set'>: 'assertSetEqual',
                          <class 'frozenset'>: 'assertSetEqual',
                          <class 'tuple'>: 'assertTupleEqual',
                          <class 'str'>: 'assertMultiLineEqual'},
 'api_session': <plone.restapi.testing.RelativeSession object at 0x108d98ef0>,
 'app': <Application at >,
 'browser': <plone.testing._z2_testbrowser.Browser object at 0x110f71b70>,
 'document': <Document at /plone/front-page>,
 'frozen_time': <freezegun.api.FrozenDateTimeFactory object at 0x11105dda0>,
 'portal': <PloneSite at /plone>,
 'portal_url': 'http://localhost:53215/plone',
 'request': <HTTPRequest, URL=None>,
 'time_freezer': <freezegun.api._freeze_time object at 0x108e1d6a0>}

I can remove several keys from it without problem:

(Pdb) del test.__dict__['_outcome']
(Pdb) del test.__dict__['request']
(Pdb) del test.__dict__['portal']
(Pdb) del test.__dict__['portal_url']
(Pdb) del test.__dict__['app']
(Pdb) del test.__dict__['browser']

But the offending one is api_session:

(Pdb) del test.__dict__['api_session']
.../zope.testrunner-4.9.2-py3.7.egg/zope/testrunner/runner.py:1:
ResourceWarning: unclosed <socket.socket fd=9, family=AddressFamily.AF_INET,
type=SocketKind.SOCK_STREAM, proto=6,
laddr=('127.0.0.1', 53217), raddr=('127.0.0.1', 53215)>

Looks like we need to close the api_session in tearDown. I will prepare a PR.

mauritsvanrees added a commit that referenced this issue Dec 27, 2018
This prevents lots of ResourceWarnings about unclosed sockets.
Fixes #636 and #648.
mister-roboto pushed a commit to plone/buildout.coredev that referenced this issue Dec 27, 2018
Branch: refs/heads/master
Date: 2018-12-27T16:58:44+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.restapi@7e57735

Close the api_session in tests.

This prevents lots of ResourceWarnings about unclosed sockets.
Fixes plone/plone.restapi#636 and plone/plone.restapi#648.

Files changed:
M CHANGES.rst
M src/plone/restapi/tests/test_documentation.py
Repository: plone.restapi

Branch: refs/heads/master
Date: 2018-12-28T00:01:34+01:00
Author: Gil Forcada Codinachs (gforcada) <gil.gnome@gmail.com>
Commit: plone/plone.restapi@fbd357b

Merge pull request #651 from plone/close-api-session

Close the api_session in tests.

Files changed:
M CHANGES.rst
M src/plone/restapi/tests/test_documentation.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants