Revert "handles AWS HTTP 503 ServiceUnavailableException similarly to 429s"

This reverts commit ffcaa23511.
This commit is contained in:
nai-degen 2024-09-09 09:43:59 -05:00
parent ffcaa23511
commit 2a6f85e2e2
2 changed files with 5 additions and 23 deletions

View File

@ -212,16 +212,11 @@ const handleUpstreamErrors: ProxyResHandlerWithBody = async (
delete errorPayload.message;
} else if (service === "gcp") {
// Try to standardize the error format for GCP
if (errorPayload.error?.code) {
// GCP Error
errorPayload.error = {
message: errorPayload.error.message,
type: errorPayload.error.status || errorPayload.error.code,
};
if (errorPayload.error?.code) { // GCP Error
errorPayload.error = { message: errorPayload.error.message, type: errorPayload.error.status || errorPayload.error.code };
}
}
// TODO: this shitshow should be switched on the service, not the error code
if (statusCode === 400) {
switch (service) {
case "openai":
@ -298,8 +293,8 @@ const handleUpstreamErrors: ProxyResHandlerWithBody = async (
errorPayload.proxy_note = `Received 403 error. Key may be invalid.`;
}
return;
case "mistral-ai":
case "gcp":
case "mistral-ai":
case "gcp":
keyPool.disable(req.key!, "revoked");
errorPayload.proxy_note = `Assigned API key is invalid or revoked, please try again.`;
return;
@ -363,18 +358,6 @@ const handleUpstreamErrors: ProxyResHandlerWithBody = async (
default:
assertNever(service);
}
} else if (statusCode === 503) {
switch (service) {
case "aws":
if (
errorPayload.error?.type === "ServiceUnavailableException" &&
errorPayload.error?.message?.match(/too many connections/i)
) {
// This is effectively a 429 rate limit error under another name.
await handleAwsRateLimitError(req, errorPayload);
}
break;
}
} else {
errorPayload.proxy_note = `Unrecognized error from upstream service.`;
}
@ -463,7 +446,6 @@ async function handleAwsRateLimitError(
) {
const errorType = errorPayload.error?.type;
switch (errorType) {
case "ServiceUnavailableException":
case "ThrottlingException":
keyPool.markRateLimited(req.key!);
await reenqueueRequest(req);

View File

@ -29,7 +29,7 @@ export interface AwsBedrockKey extends Key, AwsBedrockKeyUsage {
* Upon being rate limited, a key will be locked out for this many milliseconds
* while we wait for other concurrent requests to finish.
*/
const RATE_LIMIT_LOCKOUT = 5000;
const RATE_LIMIT_LOCKOUT = 4000;
/**
* Upon assigning a key, we will wait this many milliseconds before allowing it
* to be used again. This is to prevent the queue from flooding a key with too