MoralisWeb3 / Moralis-JS-SDK

Moralis Official Javascript SDK
https://docs.moralis.io
Other
366 stars 257 forks source link

Moralis Streams switch to paused state by themselves for unknown reason. #1108

Closed h4nz4 closed 1 year ago

h4nz4 commented 1 year ago

Hello.

I have been experimenting with Moralis on a toy project. I have created a stream manually in the Admin panel, then added an address programmatically using the Node.js SDK. The stream becomes paused randomly, by itself, after some amount of time. Why does this happen and how can it be prevented? I did not find any explaination in the documentation.

Thanks!

b4rtaz commented 1 year ago

Hi @h4nz4! Thanks for reporting. We are looking at this.

b4rtaz commented 1 year ago

@h4nz4 are you certain that you're not exceeding your account limits?

h4nz4 commented 1 year ago

The account limits cannot be the culprit here. The streams simply pause by themselves.

On 27 Apr 2023, at 15:39, Bart Tadych @.***> wrote:

@h4nz4 https://github.com/h4nz4 are you certain that you're not exceeding your account limits?

— Reply to this email directly, view it on GitHub https://github.com/MoralisWeb3/Moralis-JS-SDK/issues/1108#issuecomment-1525715390, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEM37FGPJXVOAIIH7ALTHE3XDJZK3ANCNFSM6AAAAAAXM2GY6E. You are receiving this because you were mentioned.

b4rtaz commented 1 year ago

I've executed the below code and I'm receiving data without any problems for an hour now.

Maybe your hook throws an error. The webhook should return HTTP 200.

import Moralis from 'moralis';
import { EvmChain } from '@moralisweb3/common-evm-utils';

async function main() {
  Moralis.start({
    apiKey: '<API_KEY>',
  });

  const stream = await Moralis.Streams.add({
    chains: [EvmChain.ETHEREUM],
    description: 'test sdk',
    tag: 'test',
    webhookUrl: '<WEBHOOK_URL>',
    abi: [
      {
        anonymous: false,
        inputs: [
          {
            indexed: true,
            name: 'from',
            type: 'address',
          },
          {
            indexed: true,
            name: 'to',
            type: 'address',
          },
          {
            indexed: false,
            name: 'value',
            type: 'uint256',
          },
        ],
        name: 'Transfer',
        type: 'event',
      },
    ],
    topic0: ['Transfer(address,address,uint256)'],
    includeContractLogs: true,
  });

  console.log('stream', stream.toJSON());

  const addr = await Moralis.Streams.addAddress({
    id: stream.result.id,
    address: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0',
  });

  console.log('addr', addr.toJSON());
}

main();
h4nz4 commented 1 year ago

Could the hook throwing an error cause the stream to become paused?On 28 Apr 2023, at 12:24, Bart Tadych @.> wrote: I've executed the below code and I'm receiving data without any problems for an hour now. Maybe your hook throws an error. The webhook should return HTTP 200. import Moralis from 'moralis'; import { EvmChain } from @./common-evm-utils';

async function main() { Moralis.start({ apiKey: '', });

const stream = await Moralis.Streams.add({ chains: [EvmChain.ETHEREUM], description: 'test sdk', tag: 'test', webhookUrl: '', abi: [ { anonymous: false, inputs: [ { indexed: true, name: 'from', type: 'address', }, { indexed: true, name: 'to', type: 'address', }, { indexed: false, name: 'value', type: 'uint256', }, ], name: 'Transfer', type: 'event', }, ], topic0: ['Transfer(address,address,uint256)'], includeContractLogs: true, });

console.log('stream', stream.toJSON());

const addr = await Moralis.Streams.addAddress({ id: stream.result.id, address: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', });

console.log('addr', addr.toJSON()); }

main();

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

b4rtaz commented 1 year ago

https://docs.moralis.io/streams-api/evm/error-handling

Your Stream can enter into error state on the following 2 scenarios:

- Your webhook success-rate is below 70%
- Your server is not consuming the webhooks  (...)
h4nz4 commented 1 year ago

Error state, or also paused state? Please not that the streams went into the paused state.On 28 Apr 2023, at 12:28, Bart Tadych @.***> wrote: https://docs.moralis.io/streams-api/evm/error-handling Your Stream can enter into error state on the following 2 scenarios:

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

b4rtaz commented 1 year ago

The stream will get the error state if the webhook is broken. But if you reach out the limit then the state is paused.

"status": "paused",
"statusMessage": "Streams paused because of exceeded records",
"status": "error",
"statusMessage": "Stream in error state due to too many failed webhook requests, you can activate it by either updating the stream or through the /streams/evm/{id}/status endpoint"

You may check the statusMessage for your stream by the SDK:

  const streams = await Moralis.Streams.getAll({
    limit: 20,
  });

If that won't help, please write a message to our support: hello@moralis.io More details like your account info may be necessary.

b4rtaz commented 1 year ago

@h4nz4 have you solved the problem?

h4nz4 commented 1 year ago

The problem is sadly still there. I also posted on Moralis forum, and got no helpful suggestion from the community. I would understand, if the streams went into errored state, but they switch into paused state, by themselves, and they have to be manually reset to the active state. The usage limits have never been achieved, not even 20% of the Free plan usage cap.

Please, help!

b4rtaz commented 1 year ago

What a message do you have in the statusMessage after the problem occurs?

h4nz4 commented 1 year ago

Where can this statusMessage be observed?

V V čet., 11. maj 2023 ob 11:13 je oseba Bart Tadych < @.***> napisala:

What a message do you have in the statusMessage after the problem occurs?

— Reply to this email directly, view it on GitHub https://github.com/MoralisWeb3/Moralis-JS-SDK/issues/1108#issuecomment-1543632918, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEM37FE346QJCDC43K5R6D3XFSUSVANCNFSM6AAAAAAXM2GY6E . You are receiving this because you were mentioned.Message ID: @.***>

b4rtaz commented 1 year ago

You can read it by calling the API for the list of your all streams.

  const streams = await Moralis.Streams.getAll({
    limit: 10
  })
  console.log(streams.result[0].statusMessage);
h4nz4 commented 1 year ago

I checked now. The paused streams have statusMessage "Disconnected from Demo" - what does it mean? Could this be the reason the streams pause by themselves?

b4rtaz commented 1 year ago

I have this status when:

Are you sure that you have created a stream by the SDK? Please be sure that, you don't have the admin panel opened in the background.

h4nz4 commented 1 year ago

The streams I used were created manually in the admin panel. They weren't created from the SDK. They have always been in demo mode. Could the latter cause the pausing behavior?

b4rtaz commented 1 year ago

For the demo mode it's not possible. The demo mode is only for testing purposes. You need to switch the mode to prod.

h4nz4 commented 1 year ago

I see. So this could be the origin of the problems all along?

b4rtaz commented 1 year ago

It could be. You need to test it on your side.

b4rtaz commented 1 year ago

@h4nz4 Have you tested it? Can we close this issue?

h4nz4 commented 1 year ago

I think it is better, but please wait a bit for me to verify.

b4rtaz commented 1 year ago

@h4nz4 can we close this issue?

b4rtaz commented 1 year ago

Due to inactivity I close this issue. If the problem still occurs, please open a new one.