Skip to content

Make network requests cancelable #4974

@jdm

Description

@jdm

Right now it is possible to "cancel" a network request by freeing the Receiver that corresponds to the network response (ie. when the Receiver goes out of scope), since that causes the network thread to panic when it tries to send on the closed channel. This won't be enough when we move to an event-based system instead of using channels - the network thread will just keep sending events to the target thread, and the target thread has no way to inform the network thread that the response is not wanted.

I propose the following:

  • create a new ResourceId type that wraps an integer
  • add a new optional Sender<ResourceId> argument to the Load message in ControlMsg in resource_task.rs
  • in the load handler for ResourceTask, generate a new resource id for each load that requires it, and send it on the provided Sender if it exists
  • for loads with a resource id, create a new channel and store the sender in a vector in ResourceTask, and pass the receiver to the loader factory
  • in each loader implementation, use the new optional receiver to check if a load is supposed to be cancelled at key points (after headers are received and before each read of the response)
  • add a new Cancel message to ControlMsg in resource_task.rs which takes a ResourceId, finds the corresponding entry in the vector and sends a message on corresponding termination sender

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-networkC-assignedThere is someone working on resolving the issueE-more-complexVariable effort required; may require a mentor. Recommended solution is clearly described in the iss

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions