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

[BUG] Asynchronous Client Hangs When Connecting to Non-Existent IP #270

Open
fuergaosi233 opened this issue May 28, 2024 · 0 comments · May be fixed by #271
Open

[BUG] Asynchronous Client Hangs When Connecting to Non-Existent IP #270

fuergaosi233 opened this issue May 28, 2024 · 0 comments · May be fixed by #271

Comments

@fuergaosi233
Copy link

Description:
When using an asynchronous client to connect to a non-existent IP, the program hangs indefinitely because the socket operation is pending globally. This issue causes the entire program to be stuck.

Steps to Reproduce:

  1. Use the following code to create an asynchronous client that attempts to connect to a non-existent IP.
  2. The program will hang and not proceed beyond the client connection attempt.

Code to Reproduce:

# -*- coding: utf-8 -*-
import thriftpy2
import asyncio
from thriftpy2.rpc import make_aio_client

echo_thrift = thriftpy2.load("echo.thrift", module_name="echo_thrift")
import datetime

async def print_current_time():
    while True:
        print(datetime.datetime.now())
        await asyncio.sleep(1)

async def main():
    task_current_time = asyncio.create_task(print_current_time())
    await asyncio.sleep(5)
    client = await make_aio_client(
        echo_thrift.EchoService, "100.100.100.100", 6000, connect_timeout=100* 1000
    )
    print(await client.echo("hello, world"))
    client.close()

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

Expected Behavior:
The connection attempt should timeout after the specified connect_timeout duration and raise an appropriate exception, allowing the program to handle it gracefully and don't block loop.

Actual Behavior:
The program hangs indefinitely and does not raise an exception after the timeout period. This behavior prevents the rest of the program from executing.

Environment:

  • thriftpy2 version: 0.5.1rc1
  • Python version: 3.9
  • Operating System: Debian GNU/Linux

Additional Information:
The issue appears to be related to how the socket operation is handled when connecting to an unreachable IP address. This results in the entire program being stuck, which can be problematic for applications relying on asynchronous operations.

@fuergaosi233 fuergaosi233 changed the title [BUG] Title: Asynchronous Client Hangs When Connecting to Non-Existent IP [BUG] Asynchronous Client Hangs When Connecting to Non-Existent IP May 28, 2024
@fuergaosi233 fuergaosi233 linked a pull request May 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant