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

IPC provider subscription randomly not working #4656

Closed
1 task done
francesco-clementi-92 opened this issue Dec 28, 2021 · 16 comments
Closed
1 task done

IPC provider subscription randomly not working #4656

francesco-clementi-92 opened this issue Dec 28, 2021 · 16 comments
Assignees
Labels
4.x 4.0 related Bug Addressing a bug

Comments

@francesco-clementi-92
Copy link

francesco-clementi-92 commented Dec 28, 2021

https://eips.ethereum.org/EIPS/eip-1193#events our current providers should be in compliance with this.

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I have a full node on my pc which works perfectly and I'm using web3js IPC Provider to subscribe to pending transactions.

In a random moment, more or less once every two days, the IPC stop to send pending transactions without any error and it's not a node problem as I'm constantly monitoring it.

I'm using the following code to monitor the subscription, but only the connected and data event works for now.

web3.eth.subscribe('pendingTransactions',(error, result) => {
            if(error) console.error(error);
        })
        .on("connected", async function () {
            console.log("IPC CONNECTED")
        })
        .on("close", async function () {
            console.log("IPC CLOSE")
        })
        .on("error", async function (e) {
            console.log("IPC ERROR")
        })
        .on("end", async function () {
            console.log("IPC END")
        })
        .on("timeout", async function () {
            console.log("IPC TIMEOUT")
        })
        .on("data", async function (txHash) {
              console.log(txHash)
         })

Expected Behavior

I expect an error event so I can manage this edge case or a better configuration of the IPC provider with timeout and retry config such as ws and http provider.

Steps to Reproduce

Can't find a way to reproduce it.

Web3.js Version

1.6.1

Environment

  • Operating System: Windows 10
  • Node.js Version: 16.13.1
  • NPM Version: 8.1.2

Anything Else?

No response

@francesco-clementi-92 francesco-clementi-92 added the Bug Addressing a bug label Dec 28, 2021
@francesco-clementi-92 francesco-clementi-92 changed the title IPC provider randomly not working IPC provider subscription randomly not working Dec 28, 2021
@jdevcs jdevcs added the 1.x 1.0 related issues label Jan 4, 2022
@jdevcs jdevcs mentioned this issue Jan 4, 2022
9 tasks
@nazarhussain
Copy link
Contributor

@francesco-clementi-92 That's merely impossible to reproduce on our side if that effect in longer run.

We have a configuration listener on timeout, if that happens the connection must throw error.

https://github.com/ChainSafe/web3.js/blob/8783f4d64e424456bdc53b34ef1142d0a7cee4d7/packages/web3-providers-ipc/src/index.js#L105-L107

Can you try to debug it further on your side, by disconnecting your code temporarily or by removing the socket file while node is running.

@nazarhussain nazarhussain added the Needs Clarification Requires additional input label Jan 6, 2022
@francesco-clementi-92
Copy link
Author

francesco-clementi-92 commented Jan 6, 2022

Hi @nazarhussain ,

starting the IPC provider with a node that is syncing (so not receiving pending transaction event), I have the same problem.

No timeout or error event, even if it's successfully connected, I don't know if it's normal or not.

Do you know a way to disconnect the node without stopping it?

If not l'll try to test it asap.

@nazarhussain
Copy link
Contributor

No I don't think there is a straight forward way to do it. May be you can update your code to catch the error on higher scope, then try reconnect the IPC provider.

https://github.com/ChainSafe/web3.js/blob/8783f4d64e424456bdc53b34ef1142d0a7cee4d7/packages/web3-providers-ipc/src/index.js#L201

@francesco-clementi-92
Copy link
Author

The problem is that there is no error to catch.

I found a way to replicate it, connect the IPC provider and run a subscription, then disconnect the computer from internet.

The subscription will be stucked with no error.

@nazarhussain
Copy link
Contributor

That's seems to be a real issue, but as per our priorities right now we will address it in 4.x rewrite.

@nazarhussain nazarhussain added 4.x 4.0 related and removed Needs Clarification Requires additional input labels Jan 21, 2022
@mconnelly8
Copy link

Will manually test this in the Alpha release.

@mconnelly8
Copy link

Pushing this testing out to Beta release

@mconnelly8
Copy link

@mconnelly8
Copy link

Please add your planning poker estimate with ZenHub @nazarhussain

@github-actions
Copy link

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

@github-actions github-actions bot added the Stale Has not received enough activity label Jul 17, 2022
@mconnelly8 mconnelly8 removed the Stale Has not received enough activity label Jul 18, 2022
@github-actions
Copy link

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

@github-actions github-actions bot added the Stale Has not received enough activity label Sep 17, 2022
@jdevcs jdevcs removed the Stale Has not received enough activity label Sep 19, 2022
@avkos avkos self-assigned this Nov 14, 2022
@mconnelly8 mconnelly8 removed the 1.x 1.0 related issues label Nov 15, 2022
@jdevcs
Copy link
Contributor

jdevcs commented Nov 15, 2022

https://eips.ethereum.org/EIPS/eip-1193#events our current providers should be in compliance with this.

@RaresGeo
Copy link

I am having the same issue. It seems the subscriptions are randomly stopping without emitting the 'error' event. Here is how the subscription is created.

export function getSubscription(
  chainId: number,
  eventName: DystoEventName,
  handler?: DystoLogHandler<typeof eventName>
): Subscription<Log> | undefined {
  const network = getNetworkByChainId(chainId);
  const subscription = network.web3.eth.subscribe(
    "logs",
    {
      address: network.dystoWorldPortalContract.options.address,
      topics: [getEventTopicSignature(eventName)],
    },
    (error, result) => {
      if (!error) {
        const eventObj = decodeLog(result, eventName, network);
        if (handler) {
          handler(eventName, eventObj);
        }
      }
    }
  );
  subscribedEvents[
    `${chainId}-${network.dystoWorldSpacesContract.options.address}-${eventName}`
  ] = subscription;
  return subscription;
}

Here is an example of the eventListener for 'error'

purchasedEventSub.on("error", (data: Error) => {
      Logger.error(
        `Subscription error for ${purchasedEventName} event of the contract DystoWorldPortal on chain ${chainName} - chainId ${chainId}. Error: ${stringifyError(
          data
        )}`
      );
    });

@avkos
Copy link
Contributor

avkos commented Jan 10, 2023

Thank you for your attention. Let me add a little bit of details:

  1. this task was done only for the 4.x version of web3js
  2. You may have a provider error (not a subscription error). For example, a connection error should be in the event of the provider. According to EIP-1193 provider should have these types of events: message, connect, disconnect, chainChanged, accountsChanged. But in 1.x version of web3js we have only these events: message, open, error, close. To subscribe to provider events:
web3.provider.on('error',()=>{
  // ...
})

web3.provider.on('close',()=>{
  // ...
})

web3.provider.on('open',()=>{
  // ...
})

web3.provider.on('message',()=>{
  // ...
})

Or you can separately create provider and then pass it to web3

const Web3 = require("web3");
const provider = Web3.providers.WebsocketProvider('wss:/...')
const web3 = new Web3(provider)

provider.on('error',()=>{
    // ...
})

@RaresGeo
Copy link

I have one question, I can't seem to find this in the documentation. Why do the events not come with any parameters? I'll know the provider errored out, but not why.

Thanks for the help

@avkos avkos closed this as completed Jan 11, 2023
@avkos
Copy link
Contributor

avkos commented Jan 11, 2023

If you use WebSocket as a provider error event will be the same as WebSocket connection produce.
We use isomorphic WS.
You can check events here
for example, here are error event details for WS for the server. Also, you can check error codes here

If you have any questions please ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

6 participants