PySocks icon indicating copy to clipboard operation
PySocks copied to clipboard

Workaround for a bug in Python 3.5 and 3.6 affecting UDP proxying

Open snemes opened this issue 5 years ago • 2 comments

Python versions 3.5 and 3.6 have a nasty bug related to the socket type.

In these versions, the socket type is sometimes messed up and SOCK_DGRAM (2) becomes 2050.

$ python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> sock.type
<SocketKind.SOCK_DGRAM: 2>
>>> sock.settimeout(0)
>>> sock.type
2050

(However sock.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE) still works as expected and returns the value 2.)

This unfortunately breaks the comparisons with socket.SOCK_DGRAM and makes it impossible to send UDP data through proxies (via UDPASSOCIATE/UDPREPLY). This pull request is intended to fix that, but otherwise does not change functionality. Apparently this Python bug has also been fixed in Python 3.7, but some users of PySocks might also got stuck to older versions, so this might be useful for them.

This Python bug is also briefly described in https://bugs.python.org/issue19422 (this exact issue is slightly unrelated, but triggers the same Python bug) In Python 3.7, this was fixed in https://bugs.python.org/issue32331 / https://github.com/python/cpython/pull/4877

snemes avatar Aug 05 '19 20:08 snemes

where is @Anorov ? Please accept this RP.

yuchting avatar Jun 12 '20 00:06 yuchting

No Anorov, Just me :)

molangning avatar Dec 13 '23 09:12 molangning