mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
fix(discord): bound individual api requests
An unbounded API request can outlive an update-chain lock. Bound each request so another holder cannot race a late edit.
This commit is contained in:
1 parent
a98ff778a2
commit
ffd6cf5a36
1 file changed
+7
@@ -7,6 +7,12 @@ interface DiscordMessage {
|
||||
id?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Longest a single API call may take. Bounded, so a message edit always ends
|
||||
* well within the update-chain lock it runs under (see `deliverUpdate`).
|
||||
*/
|
||||
export const REQUEST_TIMEOUT_MS = 15_000;
|
||||
|
||||
async function request(
|
||||
url: string,
|
||||
method: string,
|
||||
@@ -23,6 +29,7 @@ async function request(
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(message),
|
||||
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
||||
});
|
||||
|
||||
if (res.status === 429) {
|
||||
|
||||
Reference in new issue
Block a user