awslabs / llrt

LLRT (Low Latency Runtime) is an experimental, lightweight JavaScript runtime designed to address the growing demand for fast and efficient Serverless applications.
Apache License 2.0
7.74k stars 342 forks source link

Implement Request#signal. #312

Closed calavera closed 2 months ago

calavera commented 3 months ago

Issue # (if available)

Fixes https://github.com/awslabs/llrt/issues/182

Description of changes

Allow to pass an AbortSignal as an option to a request. Ensure that only AbortSignal types are allowed.

Checklist

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

calavera commented 3 months ago

We also need to check if signal is aborted when we use the request. Similarly the same signal should be passed to response and handle aborted value as well

@richarddavison can you point me to where that's handled? I cannot find the right place to add those checks.

richarddavison commented 3 months ago

We also need to check if signal is aborted when we use the request. Similarly the same signal should be passed to response and handle aborted value as well

@richarddavison can you point me to where that's handled? I cannot find the right place to add those checks.

First place would be to here: https://github.com/awslabs/llrt/blob/a3a9fa73700006c46ebe3171635ffb48a70d440c/src/http/fetch.rs#L175

And then when response is read: https://github.com/awslabs/llrt/blob/a3a9fa73700006c46ebe3171635ffb48a70d440c/src/http/response.rs#L133

I see two solutions:

  1. Store a broadcast channel and broadcast on signal so async tasks can be cancelled
  2. Periodically check for cancellations between async calls (may load unnecessary data)