web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.37k stars 4.96k forks source link

RequestManager/SocketProvider never resolves Web3Deferred Promise when using IPC Provider #7323

Open fipso opened 1 month ago

fipso commented 1 month ago

Steps to reproduce the behavior

const { Web3 } = require("web3");
const { IpcProvider } = require("web3-providers-ipc");

async function main2() {
  const ipcProvider = new IpcProvider("/tmp/sockets/rpc_proxy.sock", {}, {});
  const web3 = new Web3(ipcProvider);

  const latest = await web3.eth.getBlockNumber();
  console.log(latest);
}
main2();

I debugged my way to the SocketProvider's send function. For some reason, when I place a breakpoint at the end of the function return deferredPromise; line 494, wait for like 2 seconds, then i continue execution and suddenly it works and the promise resolves with the right number.

Environment

Fedora 40, Node v20.17, "web3": "^4.13.0", "web3-providers-ipc": "^4.0.7"

mconnelly8 commented 1 month ago

The team will review this soon @fipso

danforbes commented 3 weeks ago

@fipso - which Ethereum node are you connecting to with IPC? Have you checked the IPC configuration options? There is an open PR to fix the broken link to the definition of the SocketConstructorOps type - here is an updated link in the meantime.

fipso commented 3 weeks ago

Hello, the Node I am using is Nethermind. As the nethermind IPC socket is requiring a /n after each JSON object it receives I got a reverse proxy in front of it that adds a /n to each message and forwards it. I tested the reverse proxy with different nodes and client libraries so I can be sure the issue is probably not there. Thanks for pointing out the Options docs I will take a look at that

Muhammad-Altabba commented 4 days ago

Thanks for reporting the issue @fipso, We will look into it. I the mean time, it will be greate if you are able to listen to the error event on the returned deferredPromise (that is returned with return deferredPromise;). It might be very indicative for our investigation.

Muhammad-Altabba commented 4 days ago

Hi @fipso, I tested with geth and it worked well with me by printing the block number. However, you need to remember to close the connection at the end of your funciton by calling:

  ipcProvider.disconnect();

I see that your function name is main2. Do you call another function using a different connection, before running the provided code at main2, without closing that connection?