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

fix truncate size can be None #789

Merged
merged 5 commits into from Jan 18, 2024
Merged

fix truncate size can be None #789

merged 5 commits into from Jan 18, 2024

Conversation

claudius-kienle
Copy link
Contributor

If I execute a script that contains following code with gunicorn and eventlet, I get the exception that

File "/usr/local/lib/python3.8/site-packages/eventlet/greenio/py3.py", line 165, in truncate
--
Sun, Feb 12 2023 8:54:19 pm | rv = _original_os.ftruncate(self._fileno, size)
Sun, Feb 12 2023 8:54:19 pm | TypeError: an integer is required (got type NoneType)
with os.fdopen(os.open(path, os.O_WRONLY | os.O_CREAT, 0o600), 'w') as file:
            file.seek(0)
            file.write(json.dumps(token_data, indent=2))
            file.truncate()

Consequently, I assumed that truncate() must also work if size=None.
This pull request checks if size is None and in this case replaces it with -1.

@temoto
Copy link
Member

temoto commented Feb 12, 2023

Consequently, I assumed that truncate() must also work if size=None.

Why?

@temoto
Copy link
Member

temoto commented Feb 12, 2023

never mind, it's "because CPython does so" https://github.com/python/cpython/blob/main/Modules/_io/bufferedio.c#L1287

thanks for patch

@codecov
Copy link

codecov bot commented Feb 12, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (8f5ebf1) 55% compared to head (94e748e) 55%.

Files Patch % Lines
eventlet/greenio/py3.py 0% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##           master   #789   +/-   ##
=====================================
- Coverage      55%    55%   -1%     
=====================================
  Files          90     90           
  Lines        9878   9880    +2     
  Branches     1831   1832    +1     
=====================================
  Hits         5460   5460           
- Misses       4044   4045    +1     
- Partials      374    375    +1     
Flag Coverage Δ
ipv6 22% <0%> (-1%) ⬇️
py310asyncio 52% <0%> (-1%) ⬇️
py310epolls 52% <0%> (+<1%) ⬆️
py310poll 52% <0%> (-1%) ⬇️
py310selects 52% <0%> (+<1%) ⬆️
py311asyncio 52% <0%> (-1%) ⬇️
py311epolls 52% <0%> (+<1%) ⬆️
py312asyncio 49% <0%> (-1%) ⬇️
py312epolls 50% <0%> (-1%) ⬇️
py37asyncio 49% <0%> (-1%) ⬇️
py37epolls 50% <0%> (-1%) ⬇️
py38asyncio 50% <0%> (-1%) ⬇️
py38epolls 52% <0%> (-1%) ⬇️
py38openssl 51% <0%> (+<1%) ⬆️
py38poll 52% <0%> (-1%) ⬇️
py38selects 52% <0%> (-1%) ⬇️
py39asyncio 50% <0%> (-1%) ⬇️
py39dnspython1 50% <0%> (-1%) ⬇️
py39epolls 52% <0%> (-1%) ⬇️
py39poll 52% <0%> (-1%) ⬇️
py39selects 52% <0%> (-1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@itamarst itamarst added the bug label Dec 19, 2023
@4383 4383 merged commit 6ee471d into eventlet:master Jan 18, 2024
26 of 29 checks passed
@4383 4383 mentioned this pull request Jan 18, 2024
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Jan 30, 2024
* Update requirements from branch 'master'
  to 08f829d8375b4059af365191e0907069be9fb739
  - Update eventlet to 0.35.0
    
    0.35.0
    ======
    
    eventlet/eventlet#897
    
    * [fix] fix truncate size nullable eventlet/eventlet#789
    * [fix] Handle transport endpoint shutdown in conditions eventlet/eventlet#884
    * [fix] Rework reject_bad_requests option eventlet/eventlet#890
    * [fix] Fix NameError introduced by #826 eventlet/eventlet#890
    * [feature] Support awaiting GreenThread in an `async def` context eventlet/eventlet#889
    * [feature] Asyncio hub support for Python 3.7 to 3.9 eventlet/eventlet#886
    * [fix] Fix bad exceptions handlings eventlet/eventlet#883
    * [feature] Support using asyncio coroutines from inside greenlets eventlet/eventlet#877
    * [removal] Remove deprecated CGIHTTPServer and SimpleHTTPServer eventlet/eventlet#881
    * [feature] Add an asyncio hub for eventlet eventlet/eventlet#870
    
    0.34.3
    ======
    
    eventlet/eventlet#875
    
    * Fix security issue in the wsgi module related to RFC 9112 eventlet/eventlet#826
    * Fix segfault, a new approach for greening existing locks eventlet/eventlet#866
    * greendns: fix getaddrinfo parameter name eventlet/eventlet#809
    * Fix deprecation warning on ssl.PROTOCOL_TLS eventlet/eventlet#872
    * Pytests, fix error at teardown of TestGreenSocket.test_full_duplex eventlet/eventlet#871
    * Skip test which uses Py cgi module eventlet/eventlet#865
    * Drop old code based on python < 3.7.34.2
    ======
    
    eventlet/eventlet#861
    
    * Allowing inheritance of GreenSSLSocket without overriding the __new_ method eventlet/eventlet#796
    * [bug] Fix broken API related to `__version__` removal eventlet/eventlet#859
    * [doc] Fix pypi broken link eventlet/eventlet#857
    
    0.34.1
    ======
    
    eventlet/eventlet#842
    
    * [bug] Fix memory leak in greendns eventlet/eventlet#810
    * [infra] Fix OIDC authentication failure eventlet/eventlet#855
    * [bug] Ignore asyncore and asynchat for Python 3.12+ eventlet/eventlet#804
    
    0.34.0 (Not released on Pypi but landed with 0.34.1)
    ====================================================
    
    * Dropped support for Python 3.6 and earlier.
    * Fix Python 3.13 compat by adding missing attibute '_is_main_interpreter' eventlet/eventlet#847
    * Add support of Python 3.12 eventlet/eventlet#817
    * Drop unmaintained and unused stdlib tests eventlet/eventlet#820
    * Fix tests and CI for Python 3.7 and higher eventlet/eventlet#831 and eventlet/eventlet#832
    * Stop claiming to create universal wheels eventlet/eventlet#841
    * Fix green logging locks for Python versions <= 3.10 eventlet/eventlet#754
    
    Change-Id: I909be1d1812eaed574525866dbc123083684571d
openstack-mirroring pushed a commit to openstack/requirements that referenced this pull request Jan 30, 2024
0.35.0
======

eventlet/eventlet#897

* [fix] fix truncate size nullable eventlet/eventlet#789
* [fix] Handle transport endpoint shutdown in conditions eventlet/eventlet#884
* [fix] Rework reject_bad_requests option eventlet/eventlet#890
* [fix] Fix NameError introduced by #826 eventlet/eventlet#890
* [feature] Support awaiting GreenThread in an `async def` context eventlet/eventlet#889
* [feature] Asyncio hub support for Python 3.7 to 3.9 eventlet/eventlet#886
* [fix] Fix bad exceptions handlings eventlet/eventlet#883
* [feature] Support using asyncio coroutines from inside greenlets eventlet/eventlet#877
* [removal] Remove deprecated CGIHTTPServer and SimpleHTTPServer eventlet/eventlet#881
* [feature] Add an asyncio hub for eventlet eventlet/eventlet#870

0.34.3
======

eventlet/eventlet#875

* Fix security issue in the wsgi module related to RFC 9112 eventlet/eventlet#826
* Fix segfault, a new approach for greening existing locks eventlet/eventlet#866
* greendns: fix getaddrinfo parameter name eventlet/eventlet#809
* Fix deprecation warning on ssl.PROTOCOL_TLS eventlet/eventlet#872
* Pytests, fix error at teardown of TestGreenSocket.test_full_duplex eventlet/eventlet#871
* Skip test which uses Py cgi module eventlet/eventlet#865
* Drop old code based on python < 3.7.34.2
======

eventlet/eventlet#861

* Allowing inheritance of GreenSSLSocket without overriding the __new_ method eventlet/eventlet#796
* [bug] Fix broken API related to `__version__` removal eventlet/eventlet#859
* [doc] Fix pypi broken link eventlet/eventlet#857

0.34.1
======

eventlet/eventlet#842

* [bug] Fix memory leak in greendns eventlet/eventlet#810
* [infra] Fix OIDC authentication failure eventlet/eventlet#855
* [bug] Ignore asyncore and asynchat for Python 3.12+ eventlet/eventlet#804

0.34.0 (Not released on Pypi but landed with 0.34.1)
====================================================

* Dropped support for Python 3.6 and earlier.
* Fix Python 3.13 compat by adding missing attibute '_is_main_interpreter' eventlet/eventlet#847
* Add support of Python 3.12 eventlet/eventlet#817
* Drop unmaintained and unused stdlib tests eventlet/eventlet#820
* Fix tests and CI for Python 3.7 and higher eventlet/eventlet#831 and eventlet/eventlet#832
* Stop claiming to create universal wheels eventlet/eventlet#841
* Fix green logging locks for Python versions <= 3.10 eventlet/eventlet#754

Change-Id: I909be1d1812eaed574525866dbc123083684571d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants