Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip managing connection pool for single endpoint #2091

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/node-core/src/indexer/connectionPool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class ConnectionPoolService<T extends IApiConnectionSpecific<any, any, an
if (await this.poolStateManager.getFieldValue(endpoint, 'rateLimited')) {
logger.info('throtling on ratelimited endpoint');
const backoffDelay = await this.poolStateManager.getFieldValue(endpoint, 'backoffDelay');
await delay(backoffDelay);
await delay(backoffDelay / 1000);
}

const start = Date.now();
Expand Down
7 changes: 5 additions & 2 deletions packages/node-core/src/indexer/connectionPoolState.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import {OnApplicationShutdown} from '@nestjs/common';
import chalk from 'chalk';
import {toNumber} from 'lodash';
import {ApiErrorType} from '../api.connection.error';
import {IApiConnectionSpecific} from '../api.service';
import {getLogger} from '../logger';
Expand Down Expand Up @@ -91,6 +90,7 @@ export class ConnectionPoolStateManager<T extends IApiConnectionSpecific<any, an

if (rateLimitedEndpoints.length === 0) {
// If no rate-limited endpoints found, return undefined
// FIXME: We better block the promise until one endpoint is recovered from suspension
return undefined;
}

Expand Down Expand Up @@ -187,6 +187,9 @@ export class ConnectionPoolStateManager<T extends IApiConnectionSpecific<any, an
//eslint-disable-next-line @typescript-eslint/require-await
async removeFromConnections(endpoint: string): Promise<void> {
delete this.pool[endpoint];
if (Object.keys(this.pool).length === 0) {
process.exit(1);
}
}

//eslint-disable-next-line @typescript-eslint/require-await
Expand All @@ -198,7 +201,7 @@ export class ConnectionPoolStateManager<T extends IApiConnectionSpecific<any, an

//eslint-disable-next-line @typescript-eslint/require-await
async handleApiError(endpoint: string, errorType: ApiErrorType): Promise<void> {
if (this.pool[endpoint].failed || this.pool[endpoint].rateLimited) {
if (Object.keys(this.pool).length === 1 || this.pool[endpoint].failed || this.pool[endpoint].rateLimited) {
//if this api was used again then it must be in the same batch of blocks
return;
}
Expand Down
Loading