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

request.json_body generates unclosed file ResourceWarning #428

Closed
hyperknot opened this issue Mar 24, 2021 · 1 comment
Closed

request.json_body generates unclosed file ResourceWarning #428

hyperknot opened this issue Mar 24, 2021 · 1 comment

Comments

@hyperknot
Copy link

Inserting a simple request.json_body in a POST view generates a ResourceWarning: unclosed file <_io.BufferedRandom name=15>.

There is nothing else in the request, just a single line of request.json_body.

Interestingly this only happens the 2nd time a view is requested. Not the 1st, 3rd, 4th, 5th times, only the 2nd time. 100% reproducible.

Tracemalloc:

.pyenv/versions/3.7.10/lib/python3.7/json/decoder.py:353: ResourceWarning: unclosed file <_io.BufferedRandom name=15>
  obj, end = self.scan_once(s, idx)
Object allocated at (most recent call last):
  File ".pyenv/versions/3.7.10/lib/python3.7/threading.py", lineno 890
    self._bootstrap_inner()
  File ".pyenv/versions/3.7.10/lib/python3.7/threading.py", lineno 926
    self.run()
  File ".pyenv/versions/3.7.10/lib/python3.7/threading.py", lineno 870
    self._target(*self._args, **self._kwargs)
  File "venv/lib/python3.7/site-packages/waitress/task.py", lineno 84
    task.service()
  File "venv/lib/python3.7/site-packages/waitress/channel.py", lineno 397
    task.service()
  File "venv/lib/python3.7/site-packages/waitress/task.py", lineno 168
    self.execute()
  File "venv/lib/python3.7/site-packages/waitress/task.py", lineno 434
    app_iter = self.channel.server.application(environ, start_response)
  File "venv/lib/python3.7/site-packages/paste/translogger.py", lineno 69
    return self.application(environ, replacement_start_response)
  File "venv/lib/python3.7/site-packages/pyramid/router.py", lineno 274
    response = self.execution_policy(environ, self)
  File "venv/lib/python3.7/site-packages/pyramid/router.py", lineno 281
    return router.invoke_request(request)
  File "venv/lib/python3.7/site-packages/pyramid/router.py", lineno 249
    response = handle_request(request)
  File "venv/lib/python3.7/site-packages/pyramid_tm/__init__.py", lineno 143
    response = handler(request)
  File "venv/lib/python3.7/site-packages/pyramid/tweens.py", lineno 41
    response = handler(request)
  File "venv/lib/python3.7/site-packages/pyramid/router.py", lineno 148
    registry, request, context, context_iface, view_name
  File "venv/lib/python3.7/site-packages/pyramid/view.py", lineno 683
    response = view_callable(context, request)
  File "venv/lib/python3.7/site-packages/pyramid/config/views.py", lineno 188
    return view(context, request)
  File "venv/lib/python3.7/site-packages/pyramid/config/views.py", lineno 214
    return view(context, request)
  File "venv/lib/python3.7/site-packages/pyramid/viewderivers.py", lineno 325
    return view(context, request)
  File "venv/lib/python3.7/site-packages/pyramid/viewderivers.py", lineno 514
    return view(context, request)
  File "web/server/maphub_web/security.py", lineno 109
    response = view(context, request)
  File "web/server/maphub_web/security.py", lineno 93
    response = view(context, request)
  File "venv/lib/python3.7/site-packages/pyramid/viewderivers.py", lineno 436
    result = view(context, request)
  File "venv/lib/python3.7/site-packages/pyramid/viewderivers.py", lineno 144
    response = view(request)
  File "web/server/maphub_web/views/json/map/map_save.py", lineno 23
    data = request.json_body
  File "venv/lib/python3.7/site-packages/pyramid/request.py", lineno 231
    return json.loads(text_(self.body, self.charset))
  File "venv/lib/python3.7/site-packages/webob/request.py", lineno 693
    self.make_body_seekable() # we need this to have content_length
  File "venv/lib/python3.7/site-packages/webob/request.py", lineno 929
    self.copy_body()
  File "venv/lib/python3.7/site-packages/webob/request.py", lineno 979
    fileobj = self.make_tempfile()
  File "venv/lib/python3.7/site-packages/webob/request.py", lineno 1019
    return tempfile.TemporaryFile()
  File ".pyenv/versions/3.7.10/lib/python3.7/tempfile.py", lineno 622
    newline=newline, encoding=encoding)
    ```
    
WebOb==1.8.7
pyramid==1.10.8
waitress==2.0.0 (same with 1.x)

Related issues:
https://github.com/Pylons/webob/issues/416
https://github.com/Pylons/pyramid/issues/3599

@digitalresistor
Copy link
Member

Related/same issue: #427 #428 #416 #415

Closing in favor of #415

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

No branches or pull requests

2 participants