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

Deadlock upon calling await client.abort() #163

Open
michaelwillis opened this issue May 23, 2023 · 5 comments
Open

Deadlock upon calling await client.abort() #163

michaelwillis opened this issue May 23, 2023 · 5 comments

Comments

@michaelwillis
Copy link

I'm trying to implement abort download as described in Advanced download and upload, abort, restart. Following the example, I find that await client.abort() deadlocks, but if my code first calls stream.close(), then it can call await client.abort() without deadlock. Are these two lines mixed up in the example?

@pohmelie
Copy link
Collaborator

How your code looks like? Did you read the warning part? https://aioftp.readthedocs.io/client_tutorial.html#id2

@michaelwillis
Copy link
Author

Yes, I read the warning and tried to follow it. Here is my code, which is working now that it calls stream.close() and await client.abort() in reverse order from that recommended by the warning:

async with aioftp.Client.context(HOST, user=USER, password=PASSWORD) as client:
    # See note about how to abort streaming download without causing deadlock:
    # https://aioftp.readthedocs.io/client_tutorial.html#advanced-download-and-upload-abort-restart
    stream = await client.download_stream(filename)
    completed = False
    try:
        # stream_process_lines() returns false if download should be aborted
        completed = await stream_process_lines(stream)
        if completed:
            await stream.finish()
    finally:
        # Need to abort download if either stream_process_lines() returned False or an exception was raised
        if not completed:
            stream.close()
            await client.abort()

@pohmelie
Copy link
Collaborator

Can you provide some log messages? So I can release where stuck is.

@michaelwillis
Copy link
Author

Hmm, I rewrote the code as follows and it gives me almost no problems:

try:
    async with aioftp.Client.context(HOST, user=USER, password=PASSWORD) as client:
        async with client.download_stream(filename) as stream:
            await stream_process_lines(stream)
except Exception as e:
    log.error("Error processing file: %s, %s" % filename, e)

This code always exits, never deadlocks. If stream_process_lines(stream) either raises an exception or returns early without consuming the entire stream, then the end of the log statement says Waiting for ('2xx',) but got 450 [' Transfer aborted forcefully by client.'], which seems fine to me.

@pohmelie
Copy link
Collaborator

But issue exists. Maybe you can replicate the issue and provide some logs. Since I still have no clue about reasons for such behavior.

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

No branches or pull requests

2 participants