Skip to content

Does a task-cancel interrupt a TcpStream read await? #364

@h1771t

Description

@h1771t

I create a task with something like:

t = ex.spawn(do_tcp_send(payload))

But later I need to cancel the task, so I do:

t.cancel().await;

I expect that the task cancel should immediately close any TcpStream in the task? But that's not the behaviour I seem to get.

Inside the task I'm doing:

smol::net::TcpStream::connect(SERVER).await
stream.write_all(&payload.into_bytes()).await
stream.read(&mut resp).await;

I mostly cancel the task waiting for the stream read. The cancel().await returns a None so the task is not completing (which is fine), but I'm not sure the tcp connection is being closed?
On the server side if I sleep the thread after reading the request, then write a response, I'm expecting the write response to fail since the client task was cancelled? It doesn't fail, so I'm suspecting the task cancel is not closing the tcp connection.

Any advice or suggestions would be much appreciated, thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions