Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Add error handling for ensureAPIClientLiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Jan 9, 2024
1 parent 4379e3e commit b730808
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion services/blockchain-connector/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ config.apiClient = {

// Every n milliseconds, verify if client connection is alive
config.clientConnVerifyInterval =
Number(process.env.CLIENT_CONNECTION_VERIFY_INTERVAL) || 30 * 1000; // in millisecs
Number(process.env.CLIENT_CONNECTION_VERIFY_INTERVAL) || 60 * 1000; // in millisecs

// Backdoor config to restart the connector if the stall issue pops up - disabled by default
const exitDelay = Number(process.env.CONNECTOR_EXIT_DELAY_IN_HOURS); // in hours
Expand Down
1 change: 1 addition & 0 deletions services/blockchain-connector/shared/sdk/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const resetApiClient = async (apiClient, isEventSubscriptionClient = false) => {
// Replace the dead API client in the pool
if (!isObject(apiClient)) {
logger.warn(`apiClient is ${JSON.stringify(apiClient)}. Cannot reset.`);
if (isEventSubscriptionClient) Signals.get('eventSubscriptionClientReset').dispatch();
return;
}

Expand Down
40 changes: 22 additions & 18 deletions services/blockchain-connector/shared/sdk/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,31 @@ const ensureAPIClientLiveness = () => {

if (isNodeSynced && isGenesisBlockDownloaded) {
setInterval(async () => {
if (typeof eventsCounter === 'number' && eventsCounter > 0) {
eventsCounter = 0;
} else {
if (typeof eventsCounter !== 'number') {
logger.warn(
`eventsCounter ended up with non-numeric value: ${JSON.stringify(
eventsCounter,
null,
'\t',
)}.`,
);
try {
if (typeof eventsCounter === 'number' && eventsCounter > 0) {
eventsCounter = 0;
}
} else {
if (typeof eventsCounter !== 'number') {
logger.warn(
`eventsCounter ended up with non-numeric value: ${JSON.stringify(
eventsCounter,
null,
'\t',
)}.`,
);
eventsCounter = 0;
}

if (typeof eventSubscribeClientPoolIndex === 'number') {
const apiClient = await getApiClient(eventSubscribeClientPoolIndex);
Signals.get('resetApiClient').dispatch(apiClient, true);
logger.debug(
`Dispatched 'resetApiClient' signal for the event subscription API client ${apiClient.poolIndex}.`,
);
if (typeof eventSubscribeClientPoolIndex === 'number') {
const apiClient = await getApiClient(eventSubscribeClientPoolIndex);
Signals.get('resetApiClient').dispatch(apiClient, true);
logger.debug(
`Dispatched 'resetApiClient' signal for the event subscription API client ${apiClient.poolIndex}.`,
);
}
}
} catch (_) {
// No action required
}
}, config.clientConnVerifyInterval);
} else {
Expand Down

0 comments on commit b730808

Please sign in to comment.