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

Commit db6e479

Browse files
committed
Add error handling for ensureAPIClientLiveness
1 parent 4379e3e commit db6e479

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

services/blockchain-connector/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ config.apiClient = {
127127

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

132132
// Backdoor config to restart the connector if the stall issue pops up - disabled by default
133133
const exitDelay = Number(process.env.CONNECTOR_EXIT_DELAY_IN_HOURS); // in hours

services/blockchain-connector/shared/sdk/events.js

+22-18
Original file line numberDiff line numberDiff line change
@@ -139,27 +139,31 @@ const ensureAPIClientLiveness = () => {
139139

140140
if (isNodeSynced && isGenesisBlockDownloaded) {
141141
setInterval(async () => {
142-
if (typeof eventsCounter === 'number' && eventsCounter > 0) {
143-
eventsCounter = 0;
144-
} else {
145-
if (typeof eventsCounter !== 'number') {
146-
logger.warn(
147-
`eventsCounter ended up with non-numeric value: ${JSON.stringify(
148-
eventsCounter,
149-
null,
150-
'\t',
151-
)}.`,
152-
);
142+
try {
143+
if (typeof eventsCounter === 'number' && eventsCounter > 0) {
153144
eventsCounter = 0;
154-
}
145+
} else {
146+
if (typeof eventsCounter !== 'number') {
147+
logger.warn(
148+
`eventsCounter ended up with non-numeric value: ${JSON.stringify(
149+
eventsCounter,
150+
null,
151+
'\t',
152+
)}.`,
153+
);
154+
eventsCounter = 0;
155+
}
155156

156-
if (typeof eventSubscribeClientPoolIndex === 'number') {
157-
const apiClient = await getApiClient(eventSubscribeClientPoolIndex);
158-
Signals.get('resetApiClient').dispatch(apiClient, true);
159-
logger.debug(
160-
`Dispatched 'resetApiClient' signal for the event subscription API client ${apiClient.poolIndex}.`,
161-
);
157+
if (typeof eventSubscribeClientPoolIndex === 'number') {
158+
const apiClient = await getApiClient(eventSubscribeClientPoolIndex);
159+
Signals.get('resetApiClient').dispatch(apiClient, true);
160+
logger.debug(
161+
`Dispatched 'resetApiClient' signal for the event subscription API client ${apiClient.poolIndex}.`,
162+
);
163+
}
162164
}
165+
} catch (_) {
166+
// No action required
163167
}
164168
}, config.clientConnVerifyInterval);
165169
} else {

0 commit comments

Comments
 (0)