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

Update ssl.py #796

Merged
merged 2 commits into from Dec 21, 2023
Merged

Update ssl.py #796

merged 2 commits into from Dec 21, 2023

Conversation

RuitongZhu
Copy link
Contributor

replace hard coded class name to avoid inconvenience when inheriting from this class

replace hard coded class name to avoid inconvenience when inheriting from this class
@temoto
Copy link
Member

temoto commented May 7, 2023

please describe problem fixed by this patch

@codecov
Copy link

codecov bot commented May 7, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d78f8f6) 53% compared to head (9369404) 53%.
Report is 6 commits behind head on master.

Additional details and impacted files
@@          Coverage Diff          @@
##           master   #796   +/-   ##
=====================================
  Coverage      53%    53%           
=====================================
  Files          88     88           
  Lines        9848   9848           
  Branches     1841   1841           
=====================================
+ Hits         5299   5300    +1     
+ Misses       4164   4163    -1     
  Partials      385    385           
Flag Coverage Δ
ipv6 22% <0%> (ø)
py310epolls 52% <100%> (+<1%) ⬆️
py310poll 52% <100%> (-1%) ⬇️
py310selects 52% <100%> (ø)
py311epolls 52% <100%> (+<1%) ⬆️
py38epolls 52% <100%> (-1%) ⬇️
py38openssl 50% <100%> (+<1%) ⬆️
py38poll 52% <100%> (ø)
py38selects 51% <100%> (+<1%) ⬆️
py39dnspython1 50% <100%> (-1%) ⬇️
py39epolls 52% <100%> (+<1%) ⬆️
py39poll 52% <100%> (+<1%) ⬆️
py39selects 51% <100%> (ø)

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.

@damani42
Copy link

Looks good to merge, but I agree with @temoto it will be great to have more detail. Please @RuitongZhu can five more information?

@4383
Copy link
Member

4383 commented Dec 12, 2023

I think I get the point but I'm not sure this change is really needed... so yes, more details would be welcome.

I think @RuitongZhu's thougths, followed the of scenario below.

First, __class__ is a reference to the type of the current instance.

When creating a new instance of GreenSSLSocket, __class__ is hard coded with the current class name GreenSSLSocket.

So, if an eventlet user want to inherit from GreenSSLSocket , and then check the instance of its own object, the user will get compare its object to a GreenSSLSocket type (the type of parent class).

However, that's not what we get.

Consider the sample below which lead more or less to the same scenario:

class A:
    def new(cls):
        cls.__class__ = A
        return cls

class B(A):
    pass


if __name__ == "__main__":
    a = A()
    b = B()
    print(isinstance(a, A))
    print(isinstance(b, A))
    print(isinstance(b, B))
    print(type(a))
    print(type(b))

Then we obtain the following output:

True
True
True
<class '__main__.A'>
<class '__main__.B'>

So even if __class__ is hard coded by A Python is enough clever to see that b is also an instance of both B and A.

My words are just guessing about the thoughts of the author of this pull request, maybe I'm wrong.

@4383
Copy link
Member

4383 commented Dec 19, 2023

@RuitongZhu: Any feedback to share with us?

@RuitongZhu
Copy link
Contributor Author

Sorry for the late reply. It's been quite a while... I've left my previous company and lost context of the request.
But I can try and argue for the change.
From the code example @4383 provided, the function new() was never really called. Thus the code example does not make much sense.
The class assignment for GreenSSLSocket was in the construction method __new__().
If you call the new() function like below:

if __name__ == "__main__":
    a = A()
    b = B()
    b.new()
    print(isinstance(a, A))
    print(isinstance(b, A))
    print(isinstance(b, B))
    print(type(a))
    print(type(b))

You would get result:

True
True
False
<class '__main__.A'>
<class '__main__.A'>

@4383
Copy link
Member

4383 commented Dec 20, 2023

Sorry for the late reply. It's been quite a while... I've left my previous company and lost context of the request. But I can try and argue for the change. From the code example @4383 provided, the function new() was never really called. Thus the code example does not make much sense. The class assignment for GreenSSLSocket was in the construction method __new__(). If you call the new() function like below:

My bad, that's a typo, I wanted to wrote __new__( instead of new(.

However, I modified my previous example to:

  1. fix the __new__ issue
  2. better match the original use case

Here is the code:

class AnotherClass:
    pass


class A:
    def __new__(cls):
        ret = AnotherClass()
        ret.__class__ = cls
        return ret


class B(A):
    pass


if __name__ == "__main__":
    a = A()
    b = B()
    print(isinstance(a, A))
    print(isinstance(b, A))
    print(isinstance(b, B))
    print(type(a))
    print(type(b))

And even with that I still obtain the right result:

True
True
True
<class '__main__.A'>
<class '__main__.B'>

@RuitongZhu
Copy link
Contributor Author

RuitongZhu commented Dec 21, 2023

Hi @4383 , note that in your example you did not hard code the __class__ but use cls instead. That's exactly what my change was trying to do.
To illustrate the current behavior, the code shall be modified as:

class A:
    def __new__(cls):
        ret = AnotherClass()
        ret.__class__ = A
        return ret

and the result would be

True
True
False
<class '__main__.A'>
<class '__main__.A'>

@4383
Copy link
Member

4383 commented Dec 21, 2023

Indeed, I confirm that by replacing ret.__class__ = cls by ret.__class__ = A in my previous example, I'm now able to reproduce this use case.

I think we should also consider the following checks to better consider this change request:

a = A()
b = B()
print(isinstance(a, A))
print(isinstance(a, AnotherClass))
print(isinstance(b, A))
print(isinstance(b, B))
print(isinstance(b, AnotherClass))
print(type(a))
print(type(b))

Previous code will output:

True
False
True
False
False
<class '__main__.A'>
<class '__main__.A'>

@4383
Copy link
Member

4383 commented Dec 21, 2023

I don't know if this behaviour is something volunteer or not.

@RuitongZhu: From your perspective why the current behaviour is an issue? Do you remember your use case?

I'm not against merging these changes, however, now, that I'm able to reproduce, and now that changed my mind concerning my intial comment, I need to better understand your use case. I want to avoid side effect to anyone else.

@RuitongZhu
Copy link
Contributor Author

I don't know if this behaviour is something volunteer or not.

@RuitongZhu: From your perspective why the current behaviour is an issue? Do you remember your use case?

I'm not against merging these changes, however, now, that I'm able to reproduce, and now that changed my mind concerning my intial comment, I need to better understand your use case. I want to avoid side effect to anyone else.

I think it's already pretty clear from the example. For a wrapper class GreenSSLSocketWrapper to inherit from GreenSSLSocket, it has to overwrite the __new__ method since __class__ was hard coded to be GreenSSLSocket. The trouble could be saved if cis was used.

@4383
Copy link
Member

4383 commented Dec 21, 2023

I don't know if this behaviour is something volunteer or not.
@RuitongZhu: From your perspective why the current behaviour is an issue? Do you remember your use case?
I'm not against merging these changes, however, now, that I'm able to reproduce, and now that changed my mind concerning my intial comment, I need to better understand your use case. I want to avoid side effect to anyone else.

I think it's already pretty clear from the example. For a wrapper class GreenSSLSocketWrapper to inherit from GreenSSLSocket, it has to overwrite the __new__ method since __class__ was hard coded to be GreenSSLSocket. The trouble could be saved if cis was used.

Got it.
Thanks for the details and for the discussion.

Copy link
Member

@4383 4383 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the details given in the discussion, these changes LGTM.

@4383 4383 merged commit 4305374 into eventlet:master Dec 21, 2023
17 checks passed
openstack-mirroring pushed a commit to openstack/requirements that referenced this pull request Jan 16, 2024
Several important and urgent fixes are released there.

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: Ib2e59a207b86ae90fa391bf1dff7819851dc9c9b
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Jan 16, 2024
* Update requirements from branch 'master'
  to 827a86739e66ffb537b5ea7a65a3cc74eb3fabf1
  - Merge "Update eventlet to 0.34.3"
  - Update eventlet to 0.34.3
    
    Several important and urgent fixes are released there.
    
    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: Ib2e59a207b86ae90fa391bf1dff7819851dc9c9b
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Jan 21, 2024
https://build.opensuse.org/request/show/1139942
by user dirkmueller + anag+factory
- update to 0.34.3:
  * Fix security issue in the wsgi module related to RFC 9112
  * Fix segfault, a new approach for greening existing locks
  * greendns: fix getaddrinfo parameter name
  * Fix deprecation warning on ssl.PROTOCOL_TLS
  * Pytests, fix error at teardown of
    TestGreenSocket.test_full_duplex
  * Skip test which uses Py cgi module
  * Drop old code based on python < 3.7
  * Allowing inheritance of GreenSSLSocket without overriding the
    __new_ method eventlet/eventlet#796
  * [bug] Fix broken API related to `__version__` removal
  * [doc] Fix pypi broken link
  * 0.34.1
  * [bug] Fix memory leak in greendns
  * [infra] Fix OIDC authentication failure
  * [bug] Ignore asyncore and asynchat for Python 3.12+
  * 0.34.0 (Not released on Pypi)
  * Dropp
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
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Feb 7, 2024
https://build.opensuse.org/request/show/1139942
by user dirkmueller + anag+factory
- update to 0.34.3:
  * Fix security issue in the wsgi module related to RFC 9112
  * Fix segfault, a new approach for greening existing locks
  * greendns: fix getaddrinfo parameter name
  * Fix deprecation warning on ssl.PROTOCOL_TLS
  * Pytests, fix error at teardown of
    TestGreenSocket.test_full_duplex
  * Skip test which uses Py cgi module
  * Drop old code based on python < 3.7
  * Allowing inheritance of GreenSSLSocket without overriding the
    __new_ method eventlet/eventlet#796
  * [bug] Fix broken API related to `__version__` removal
  * [doc] Fix pypi broken link
  * 0.34.1
  * [bug] Fix memory leak in greendns
  * [infra] Fix OIDC authentication failure
  * [bug] Ignore asyncore and asynchat for Python 3.12+
  * 0.34.0 (Not released on Pypi)
  * Dropp
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Feb 7, 2024
https://build.opensuse.org/request/show/1139942
by user dirkmueller + anag+factory
- update to 0.34.3:
  * Fix security issue in the wsgi module related to RFC 9112
  * Fix segfault, a new approach for greening existing locks
  * greendns: fix getaddrinfo parameter name
  * Fix deprecation warning on ssl.PROTOCOL_TLS
  * Pytests, fix error at teardown of
    TestGreenSocket.test_full_duplex
  * Skip test which uses Py cgi module
  * Drop old code based on python < 3.7
  * Allowing inheritance of GreenSSLSocket without overriding the
    __new_ method eventlet/eventlet#796
  * [bug] Fix broken API related to `__version__` removal
  * [doc] Fix pypi broken link
  * 0.34.1
  * [bug] Fix memory leak in greendns
  * [infra] Fix OIDC authentication failure
  * [bug] Ignore asyncore and asynchat for Python 3.12+
  * 0.34.0 (Not released on Pypi)
  * Dropp
tanaypf9 pushed a commit to tanaypf9/pf9-requirements that referenced this pull request May 20, 2024
Several important and urgent fixes are released there.

0.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: Ib2e59a207b86ae90fa391bf1dff7819851dc9c9b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants