proxybroker2 icon indicating copy to clipboard operation
proxybroker2 copied to clipboard

Fix Windows NotImplementedError / Hanging of program

Open ziloka opened this issue 1 year ago • 11 comments

The ProxyBroker program will hang when the find command (at least, the only thing tested) is executed.

This PR allows proxybroker to be used on python 3.11.0 and returns some output.

3.12.0 does not work due to not being able to compile aiohttp not supporting 3.12

Summary by CodeRabbit

  • Refactor
    • Enhanced event loop handling for better compatibility with Windows systems, including setting platform-specific policies and explicitly creating new event loops in multiple components and scripts.

ziloka avatar Nov 13 '23 01:11 ziloka

Apply Sweep Rules to your PR?

  • [ ] Apply: All new business logic should have corresponding unit tests.
  • [ ] Apply: Refactor large functions to be more modular.

sweep-ai[bot] avatar Nov 13 '23 01:11 sweep-ai[bot]

@ziloka awesome. I see tests failed because they were testing aiodns. Would you mind update those tests to dnspython too? BTW, can also add 3.11.0 into CI test python version. :smiley:

bluet avatar Dec 05 '23 18:12 bluet

Relate to #113

bluet avatar Dec 06 '23 19:12 bluet

I need to add a fix .

I don't think this works just yet, sorry

ziloka avatar Dec 09 '23 20:12 ziloka

The program stops hanging but it is slow.

Python 3.11 and python 3.12 will work but it will have (deprecation?) warnings about Transport Sockets.

Note that I only tested the find command

ziloka avatar Jan 17 '24 21:01 ziloka

I am unable to convert this into a "ready" pull request

ziloka avatar Jan 17 '24 22:01 ziloka

We might want to look into this issue https://github.com/aiortc/aioquic/issues/289

ziloka avatar Jan 18 '24 01:01 ziloka

Quality Gate Failed Quality Gate failed

Failed conditions

16.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

sonarqubecloud[bot] avatar Jan 18 '24 01:01 sonarqubecloud[bot]

This pull request does not resolve the serve issue.

To fix that issue, I believe it is necessary to migrate from asyncio to trio. See this stackoverflow comment for my reasons. An additional reason is that the examples need to be updated and it would be inconvenient and unnecessary for applications who use this upstream to put

if sys.platform == 'win32':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

In their code.

I would like to know the other maintainer's thoughts before making a merge for this.

ziloka avatar Jan 19 '24 03:01 ziloka

Walkthrough

The overarching modification across the updated files involves enhancing the handling and initialization of the asyncio event loop, particularly focusing on compatibility with Windows systems. This is achieved by explicitly importing the sys module, setting the event loop policy for Windows, creating new event loops, and passing these loops directly to constructors without relying on default event loop retrieval methods. These changes streamline event loop management and ensure more reliable operation across different platforms.

Changes

Files Change Summary
examples/basic.py, examples/find_and_save.py, examples/find_and_use.py, examples/only_grab.py, examples/proxy_server.py, examples/proxy_smtp_port.py, examples/use_existing_proxy.py Added sys import, set event loop policy for Windows, explicitly created and set new event loops, passed event loop to Broker constructor.
proxybroker/api.py, proxybroker/checker.py, proxybroker/cli.py, proxybroker/judge.py, proxybroker/providers.py, proxybroker/resolver.py, proxybroker/server.py Modified event loop initialization and handling: directly assigned loop parameter, removed default assignment or fallback to asyncio.get_event_loop().

🐰✨
Changes abound, both near and far,
In code where async streams do flow.
A rabbit hopped, beneath a star,
To fix the loops and make them glow.
🌟🔄
With every hop, a bug did flee,
And Windows found a friend in thee.
🐰✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

coderabbitai[bot] avatar Mar 18 '24 18:03 coderabbitai[bot]

Quality Gate Failed Quality Gate failed

Failed conditions
16.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

sonarqubecloud[bot] avatar Mar 25 '24 21:03 sonarqubecloud[bot]