ProjectOpenSea / stream-js

A TypeScript SDK to receive pushed updates from OpenSea over websocket.
https://docs.opensea.io/reference/stream-api-overview
MIT License
165 stars 50 forks source link

Channel disconnecting/reconnecting #310

Closed lamolivier closed 1 year ago

lamolivier commented 1 year ago

Hello,

I am using the SDK for listening at transactions on a few collections as follows (I am using onEvents because I plan to listen to more than just the item_sold event_type):

// Subscribe to event
client.onEvents(
  slug,
  [EventType.ITEM_SOLD],
  (event) => {

    // handle event
    my_function(event);
  }
);

However, I get the following outputs when running my code:

[ERROR]: {}
[ERROR]: {}
Tue Jul 04 2023 16:10:21 GMT+0200 (Central European Summer Time): Inserted 0 rows
[ERROR]: {}
[ERROR]: {}
[ERROR]: {}
Tue Jul 04 2023 16:10:23 GMT+0200 (Central European Summer Time): Inserted 0 rows
[ERROR]: {}
[ERROR]: {}
Tue Jul 04 2023 16:10:25 GMT+0200 (Central European Summer Time): Inserted 0 rows
[ERROR]: {}
Tue Jul 04 2023 16:10:27 GMT+0200 (Central European Summer Time): Inserted 0 rows
[ERROR]: {}
Tue Jul 04 2023 16:10:29 GMT+0200 (Central European Summer Time): Inserted 0 rows
Tue Jul 04 2023 16:10:31 GMT+0200 (Central European Summer Time): Inserted 0 rows
Tue Jul 04 2023 16:10:33 GMT+0200 (Central European Summer Time): Inserted 0 rows
[ERROR]: {}
Tue Jul 04 2023 16:10:35 GMT+0200 (Central European Summer Time): Inserted 0 rows
Tue Jul 04 2023 16:10:37 GMT+0200 (Central European Summer Time): Inserted 0 rows
Tue Jul 04 2023 16:10:39 GMT+0200 (Central European Summer Time): Inserted 0 rows
[INFO]: "Successfully joined channel \"collection:deadfellaz\""
[INFO]: "Successfully joined channel \"collection:meebits\""
[INFO]: "Successfully joined channel \"collection:world-of-women-nft\""
[INFO]: "Successfully joined channel \"collection:cryptoadz-by-gremplin\""
[INFO]: "Successfully joined channel \"collection:beanzofficial\""
[INFO]: "Successfully joined channel \"collection:milady\""
[INFO]: "Successfully joined channel \"collection:moonbirds-oddities\""
[INFO]: "Successfully joined channel \"collection:cool-cats-nft\""
[INFO]: "Successfully joined channel \"collection:boredapeyachtclub\""
[INFO]: "Successfully joined channel \"collection:mutant-ape-yacht-club\""
[INFO]: "Successfully joined channel \"collection:azuki\""

As you can see, I print the number of listened transactions every two seconds. This happened after 30 minutes of run. It seems like the channel has been disconnecting so it throws the ERROR log and reconnects automatically with the INFO log.

Can you confirm that this is the case ? I modified the source code for the ERROR log as below and the ERROR log doesn't help. If the channels disconnect / reconnect automatically, do you have a solution for preventing this behaviour ? It would be nice so that we do not miss any events during the disconnecting/reconnecting process.

private error(message: unknown) {
  if (this.logLevel <= LogLevel.ERROR) {
    console.error(`[ERROR]: ${JSON.stringify(message)}`); // Stringify here otherwise we get only [Object object] log
  }
}
ryanio commented 1 year ago

can you share a fully reproducible code snippet to recreate the issue? otherwise it's hard to understand what in your code might be causing this.

what happens if you just console.log(event) in onEvents, are you getting the proper event data there?

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.