Skip to content
New issue

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

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

Already on GitHub? # to your account

[Cygwin] IS_WINDOWS returns False with Windows 10 #1169

Closed
cat-policlot opened this issue May 26, 2022 · 10 comments
Closed

[Cygwin] IS_WINDOWS returns False with Windows 10 #1169

cat-policlot opened this issue May 26, 2022 · 10 comments
Assignees
Labels
Bug Bug report in proxy server

Comments

@cat-policlot
Copy link

When I try to use proxy.py, it gives an error

Tested on:
cygwin python 3.9.10;
windows 10 home edition python 3.10.4

Error in the screenshots

изображение
изображение

@cat-policlot cat-policlot added the Bug Bug report in proxy server label May 26, 2022
@abhinavsingh
Copy link
Owner

abhinavsingh commented May 26, 2022

Thank you for reporting this.

Under _env_threadless_compliant method we automatically disable multiprocessing based execution on windows. But likely, this function is not picking up that it is running on windows when in cygwin environment.

Some rationale can be found here https://github.com/abhinavsingh/proxy.py#threads-vs-threadless . Find below link to that function. Can you check if this function returns True or False for your environment. Likely, IS_WINDOWS constant is not True when running on cygwin. Please help confirm

https://github.com/abhinavsingh/proxy.py/blob/develop/proxy/common/constants.py#L25-L31

@cat-policlot
Copy link
Author

cat-policlot commented May 26, 2022

>>> IS_WINDOWS
False
>>>
>>>
>>>
>>> proxy.common.constants._env_threadless_compliant()
True
>>>

cygwin

@abhinavsingh
Copy link
Owner

cygwin

There you go, so looks like we need to get this fixed. I'll push this out this week sometime and cut a new release. Thank you for reporting this again.

@abhinavsingh
Copy link
Owner

Meanwhile, can you locally make this function return False and see if you get any errors then? Thank you!!!

@abhinavsingh abhinavsingh changed the title proxy.py 2.4.2 error in windows 10 and cygwin [Cygwin] IS_WINDOWS returns False with Windows 10 May 26, 2022
@cat-policlot
Copy link
Author

I rewrote the function, the errors did not change

def _env_threadless_compliant() -> bool:
    """Returns true for Python 3.8+ across all platforms
    except Windows."""
    return False #not IS_WINDOWS and sys.version_info >= (3, 8)
$ python -m proxy --port 1337
2022-05-26 17:36:59,830 - pid:1829 [I] plugins.load:85 - Loaded plugin proxy.http.proxy.HttpProxyPlugin
2022-05-26 17:36:59,882 - pid:1829 [I] tcp.listen:80 - Listening on 127.0.0.1:1337
2022-05-26 17:37:00,291 - pid:1829 [I] pool.setup:105 - Started 4 acceptors in threaded mode
Process Acceptor-1:
Process Acceptor-2:
Process Acceptor-3:
Process Acceptor-4:
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/drime/.local/lib/python3.9/site-packages/proxy/core/acceptor/acceptor.py", line 162, in run
    self._recv_and_setup_socks()
  File "/home/drime/.local/lib/python3.9/site-packages/proxy/core/acceptor/acceptor.py", line 162, in run
    self._recv_and_setup_socks()
  File "/home/drime/.local/lib/python3.9/site-packages/proxy/core/acceptor/acceptor.py", line 162, in run
    self._recv_and_setup_socks()
  File "/home/drime/.local/lib/python3.9/site-packages/proxy/core/acceptor/acceptor.py", line 188, in _recv_and_setup_socks
    fileno = recv_handle(self.fd_queue)
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/drime/.local/lib/python3.9/site-packages/proxy/core/acceptor/acceptor.py", line 188, in _recv_and_setup_socks
    fileno = recv_handle(self.fd_queue)
  File "/home/drime/.local/lib/python3.9/site-packages/proxy/core/acceptor/acceptor.py", line 188, in _recv_and_setup_socks
    fileno = recv_handle(self.fd_queue)
  File "/usr/lib/python3.9/multiprocessing/reduction.py", line 189, in recv_handle
    return recvfds(s, 1)[0]
  File "/home/drime/.local/lib/python3.9/site-packages/proxy/core/acceptor/acceptor.py", line 162, in run
    self._recv_and_setup_socks()
  File "/usr/lib/python3.9/multiprocessing/reduction.py", line 189, in recv_handle
    return recvfds(s, 1)[0]
  File "/usr/lib/python3.9/multiprocessing/reduction.py", line 189, in recv_handle
    return recvfds(s, 1)[0]
  File "/usr/lib/python3.9/multiprocessing/reduction.py", line 164, in recvfds
    raise RuntimeError('received %d items of ancdata' %
  File "/home/drime/.local/lib/python3.9/site-packages/proxy/core/acceptor/acceptor.py", line 188, in _recv_and_setup_socks
    fileno = recv_handle(self.fd_queue)
  File "/usr/lib/python3.9/multiprocessing/reduction.py", line 164, in recvfds
    raise RuntimeError('received %d items of ancdata' %
  File "/usr/lib/python3.9/multiprocessing/reduction.py", line 164, in recvfds
    raise RuntimeError('received %d items of ancdata' %
  File "/usr/lib/python3.9/multiprocessing/reduction.py", line 189, in recv_handle
    return recvfds(s, 1)[0]
RuntimeError: received 0 items of ancdata
  File "/usr/lib/python3.9/multiprocessing/reduction.py", line 164, in recvfds
    raise RuntimeError('received %d items of ancdata' %
RuntimeError: received 0 items of ancdata
RuntimeError: received 0 items of ancdata
RuntimeError: received 0 items of ancdata

@abhinavsingh
Copy link
Owner

@cat-policlot Thank you for the update. Looks like even though threaded mode was enabled, internal core is trying to use recv_handle for socket sharing. This results into error because it's a multiprocessing related features, main reason we wanted threaded execution to start with.

I'll leave this open. And try to revisit it sometime next week. Need to check if we can modify core to remove need of recv_handle and send_handle utility for threaded mode executions.

@cat-policlot
Copy link
Author

ok, but what about the error on windows 10, where I use powershell with python 3.10.4?

https://user-images.githubusercontent.com/44433191/170477804-3e7c29ee-fa9b-4920-96c4-bece37170e2c.png

@abhinavsingh
Copy link
Owner

@cat-policlot WINERROR 10022 indicates an invalid argument was supplied. This could happen for a variety of reasons, sometimes outside of proxy.py control. E.g. this can happen if underlying socket was unable to bind to the port, but next we are trying to listen to it. As far as I remember, there is no assertion check of whether bind succeeded. We just proceed assuming it did worked.

One thing you could try is to run proxy.py from an administrative terminal. I remember on Windows you could right click and open a shell as admin. See if that helps. Let me know. Best

abhinavsingh added a commit that referenced this issue Jun 15, 2022
* Add a context manager test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* `IS_WINDOWS` must also be True for cygwin environments.  Addresses #1169

* Give an acceptor join timeout of 10 seconds instead of None

* Reduce timeout to just 1 sec

* Install necessary types (requests is translative dep)

* Remove conflicting types

* Give precommit the necessary type

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@abhinavsingh
Copy link
Owner

@cat-policlot jFYI, IS_WINDOWS detection was fixed in #1196. Can you give it a try when you get a chance.

Also were you able to figure out WINERROR problem. Was it simply related to administrative terminal and/or how python/pip is setup locally? Can you kindly confirm.

Today, I tried proxy.py on Windows 11 + Python 3.9 combination. And it seemed to work fine. I routed entires windows traffic via proxy and I had a smooth experience.

I'll also give a try to Windows 10 + Python 3.9 combination where you faced the WINERROR. Though, I am unsure if I'll be able to reproduce it. Let me know if you had any findings related to it.

Best

@abhinavsingh
Copy link
Owner

@cat-policlot Closing this since IS_WINDOWS detection was fixed in #1196. However, I haven't had a chance to try it out yet. Someone with access to Cygwin must verify the fix. Please reopen/contribute if there is bug in this detection. Thank you

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug Bug report in proxy server
Projects
None yet
Development

No branches or pull requests

2 participants