Skip to content

Commit

Permalink
Minor refactoring to improve events server subscription handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lukecaan committed Dec 16, 2024
1 parent 0a9259f commit 7a5d2a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 8 additions & 4 deletions sdk/src/events/eventSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,14 @@ 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

0 comments on commit 7a5d2a8

Please sign in to comment.