-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Ethers Version
6.4.1
Search Terms
cancel, abort signal, https agent
Describe the Problem
I cannot find a way to cancel a Json RPC request inflight, with the v6 library (specifically to set a timeout).
All the methods I've tried, appear not to work, and I can't see anything in the documentation.
Attempt #1 (Bug)
Attempt: Set the timeout field to 1 (ms) on the FetchRequest.
Expected: requests to cancel effectively immediately.
Result: Requests still complete successfully after a duration of approx half a second.
const fetchRequest = new ethers.FetchRequest(network)
fetchRequest.timeout = 1
fetchRequest.preflightFunc = async (req: ethers.FetchRequest): Promise<ethers.FetchRequest> => {
req.timeout = 1
return req
}Attempt #2 (Bug)
Attempt: Call the FetchRequest.cancel() function.
Expected: requests to cancel mid flight
Result: request throws error "request has not been sent" (I have a long request, I'd expect it to at least have been initialised after 50ms)
const fetchRequest = new ethers.FetchRequest(network)
fetchRequest.preflightFunc = async (req: ethers.FetchRequest): Promise<ethers.FetchRequest> => {
setTimeout(() => req.cancel(), 50)
return req
}Attempt 3 (Feature request)
Attempt: Supply an AbortSignal or FetchCancelSignal in the preflightFunc
Expected: ability to set a custom abort signal
Result: there is no documented or visible way to set an abort signal
Note: Additionally, #signals are not copied during the clone() function.
Attempt 4 (Feature request)
Attempt: Supply a custom Https Agent
Expected: most libraries provide the ability to override or set the underlying Https Agent (e.g. in v5)
Result: this is no longer supported
Code Snippet
Code snippets provided inline.Contract ABI
N/AErrors
No response
Environment
node.js (v12 or newer)
Environment (Other)
Node: v18.3.0