mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-16 21:05:29 +02:00
fix(http): stop unhandled rejections from the fetch cleanup path (#3566)
* fix(http): stop unhandled rejections from the fetch cleanup path The request/body cleanup commands are fired as floating promises, and the Rust side releases a resource only once: fetch_cancel_body is resources_table.close(rid)?, and fetch_read_body also closes the rid at end-of-body. So every release after the first rejects with BadResourceId into a promise nobody is listening to. Make dropBody idempotent and let both cleanup calls handle their own rejection. * chore: add changefile * chore(http): rebuild api-iife.js
This commit is contained in:
@@ -199,14 +199,14 @@ export async function fetch(
|
||||
}
|
||||
})
|
||||
|
||||
const abort = () => invoke('plugin:http|fetch_cancel', { rid })
|
||||
const abort = () =>
|
||||
invoke('plugin:http|fetch_cancel', { rid }).catch(() => {})
|
||||
|
||||
// Optimistically check for abort signal
|
||||
// and avoid doing any work after doing intial work on the Rust side
|
||||
if (signal?.aborted) {
|
||||
// we don't care about the result of this proimse
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
abort()
|
||||
// we don't care about the result of this promise
|
||||
void abort()
|
||||
throw new Error(ERROR_REQUEST_CANCELLED)
|
||||
}
|
||||
|
||||
@@ -230,8 +230,13 @@ export async function fetch(
|
||||
rid
|
||||
})
|
||||
|
||||
let bodyDropped = false
|
||||
const dropBody = () => {
|
||||
return invoke('plugin:http|fetch_cancel_body', { rid: responseRid })
|
||||
if (bodyDropped) return Promise.resolve()
|
||||
bodyDropped = true
|
||||
return invoke('plugin:http|fetch_cancel_body', { rid: responseRid }).catch(
|
||||
() => {}
|
||||
)
|
||||
}
|
||||
|
||||
const readChunk = async (
|
||||
|
||||
Reference in New Issue
Block a user