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

Minor refactoring to improve events server subscription handling #1384

Closed
wants to merge 3 commits into from
Closed
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
18 changes: 14 additions & 4 deletions sdk/src/events/eventSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,20 @@ export class EventSubscriber {
this.logProvider.eventEmitter.on(
'reconnect',
async (reconnectAttempts) => {
if (reconnectAttempts > logProviderConfig.maxReconnectAttempts) {
console.log(
`EventSubscriber: Reconnect attempts ${reconnectAttempts}/${logProviderConfig.maxReconnectAttempts}, reconnecting...`
);
const hitMaxReconnectAttempts =
reconnectAttempts > logProviderConfig.maxReconnectAttempts;

console.log(
`EventSubscriber: Reconnect attempts ${reconnectAttempts}/${
logProviderConfig.maxReconnectAttempts
}, ${
hitMaxReconnectAttempts
? 'Falling Back...'
: 'Reconnecting...'
}`
);

if (hitMaxReconnectAttempts) {
this.logProvider.eventEmitter.removeAllListeners('reconnect');
await this.unsubscribe();
this.updateFallbackProviderType(
Expand Down
12 changes: 11 additions & 1 deletion sdk/src/events/eventsServerLogProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,17 @@ export class EventsServerLogProvider implements LogProvider {
if (parsedData.message !== undefined) {
return;
}
const event = JSON.parse(parsedData.data);
let event = JSON.parse(parsedData.data);

try {
// Handling for double-serialised events
if (typeof event === 'string') {
event = JSON.parse(event);
}
} catch (error) {
// swallow
}

this.callback(
event.txSig,
event.slot,
Expand Down
Loading