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

WebSocket RPC is not working #700

Open
kostysh opened this Issue Nov 15, 2018 · 9 comments

Comments

Projects
None yet
4 participants
@kostysh
Copy link

kostysh commented Nov 15, 2018

It seems that WebSocket feature is not working in the RSK node. I have been trying to resolve this issue via official gitter channel but with no success, so I created this issue.

My system configuration.
I am starting RSK (testnet) on the latest Ubuntu LTS server using Docker config.
Docker container config (Dockerfile, node.config, supervisord.conf, etc) is available here:https://github.com/pandoraboxchain/pyrrha/tree/master/containers/rsktest

node.conf:

blockchain.config.name = "testnet"

database.dir = /var/lib/rsk/database/testnet

rpc {

    providers {
        web {
            cors: "*",
            http {
                enabled = true
                bind_address = "0.0.0.0"
                hosts = ["localhost", "0.0.0.0", "node.rsk.pandora.network"]
                port: 4444
            }
            ws {
                enabled = true
                bind_address = "0.0.0.0"
                hosts = ["localhost", "0.0.0.0", "node.rsk.pandora.network"]
                port: 4445
            }
        }
    }

    modules = [
        { name: "eth", version: "1.0", enabled: "true" },
        { name: "net", version: "1.0", enabled: "true" },
        { name: "rpc", version: "1.0", enabled: "true" },
        { name: "web3", version: "1.0", enabled: "true" },
        { name: "evm", version: "1.0", enabled: "true" },
        { name: "sco", version: "1.0", enabled: "true" },
        { name: "txpool", version: "1.0", enabled: "true" },
        { name: "debug", version: "1.0", enabled: "true" },        
        { name: "personal", version: "1.0", enabled: "true" }
    ]
}

wallet {
    enabled = true,
    accounts = []
}

prune {
    enabled = true

    blocks {
        toCopy = 5000
        toWait = 10000
        toAvoidForks = 100
    }
}

You can start Docker container using

docker-compose up

Here the log of started node:

node_rsk    | /usr/lib/python2.7/dist-packages/supervisor/options.py:298: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
node_rsk    |   'Supervisord is running as root and it is searching '
node_rsk    | 2018-11-15 13:48:39,265 CRIT Supervisor running as root (no user in config file)
node_rsk    | 2018-11-15 13:48:39,265 INFO Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
node_rsk    | 2018-11-15 13:48:39,279 INFO RPC interface 'supervisor' initialized
node_rsk    | 2018-11-15 13:48:39,279 CRIT Server 'unix_http_server' running without any HTTP authentication checking
node_rsk    | 2018-11-15 13:48:39,279 INFO supervisord started with pid 1
node_rsk    | 2018-11-15 13:48:40,288 INFO spawned: 'rsk' with pid 10
node_rsk    | 2018-11-15 13:48:41,290 INFO success: rsk entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

As you can see above, WebSocket feature is enabled in the node.conf and the server has to listen to the port 4445 but it doesn’t. All connections to this port are immediately rejected.

Our RSK node is here: http://node.rsk.pandora.network
You can check the WebSocket connection with the online tool http://www.websocket.org/echo.html
or using curl utility:

curl --include \
     --no-buffer \
     --header "Connection: Upgrade" \
     --header "Upgrade: websocket" \
     --header "Host: node.rsk.pandora.network:80" \
     --header "Origin: http://node.rsk.pandora.network:4445" \
     http://node.rsk.pandora.network:4445

the connection result is:

curl: (56) Recv failure: Connection reset by peer

Also, you can check the WebSocket connection via latest web3 instance. Here is the test case:

import web3 from 'web3';

try {
    const webSocketProvider = new web3.providers.WebsocketProvider('ws://node.rsk.pandora.network:4445/');

    if (webSocketProvider.connection.readyState === webSocketProvider.connection.CONNECTING) {
        webSocketProvider.on('connect', () => console.log('Connected!!!'));
    } else {
        console.log('Connection state:', webSocketProvider.connection.readyState)
    }
} catch (err) { console.error(err); }

The expected behaviour is: "Connected!!!" in the console, but what we really get is just an exception:

WebSocket connection to 'ws://node.rsk.pandora.network:4445/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
@tinchou

This comment has been minimized.

Copy link
Contributor

tinchou commented Nov 16, 2018

I'm not sure if this is your only problem, but try connecting to ws://url:port/websocket.

If it doesn't work, please try running the following example first, to find out if there's anything else missing. I just ran it so it should work fine.

node.conf

blockchain.config.name = regtest
rpc.providers.web.ws.enabled = true

example.js (needs web3@1.0.0-beta.36)

var Web3 = require('web3');
var web3 = new Web3('ws://localhost:4445/websocket');

var subscription = web3.eth.subscribe(
    'newBlockHeaders',
    function (err, blockHeader, sub, existingReceipt) {
        console.log("blockHeader", blockHeader);
        subscription.unsubscribe(function() {
            console.log('Successfully unsubscribed!');
            web3.currentProvider.connection.close();
        });
    });
@kostysh

This comment has been minimized.

Copy link

kostysh commented Nov 16, 2018

No, it does not work.
I have created a test case in the separate repository https://github.com/pandoraboxchain/rsk-test-node
Here the config with enabled WebSocket feature: https://github.com/pandoraboxchain/rsk-test-node/blob/master/node.conf
Here the script for testing (slightly modified where you can see the error): https://github.com/pandoraboxchain/rsk-test-node/blob/master/test/websocket.test.js

Starting the node:

npm i
npm run build
npm run start

Starting the test:

node ./test/websocket.test.js

You will get the error immediately after start and connection will be closed.
If you will try to run web3.eth.subscribe before the connect event (as in your example above) you will get the error connection not open on send

@kostysh

This comment has been minimized.

Copy link

kostysh commented Nov 16, 2018

That strange thing - as I can seen in the rskj source - the message RPC WebSocket enabled should be shown at node start, but I can not see this message. Maybe WebSocket configuration in the node.conf is not enough?

@kostysh

This comment has been minimized.

Copy link

kostysh commented Nov 19, 2018

Is were any progress on this issue?
more details: I have tried two versions of 'rskj' from the ppa:rsksmart/rskj (0.5.2.1 & 0.5.3) and got the same result - WebSocket server not working

@tinchou

This comment has been minimized.

Copy link
Contributor

tinchou commented Nov 21, 2018

Sorry it's taking us some time, but we have many tasks on our hands right now. We will take a look at the repro soon, thanks for providing that.

By the way, could this be a Docker configuration issue by any chance? In the meantime you could try:

  • running both the node and WebSockets client from within the container
  • running both without Docker
@kostysh

This comment has been minimized.

Copy link

kostysh commented Nov 21, 2018

Sorry it's taking us some time, but we have many tasks on our hands right now. We will take a look at the repro soon, thanks for providing that.

By the way, could this be a Docker configuration issue by any chance? In the meantime you could try:

  • running both the node and WebSockets client from within the container
  • running both without Docker

It is definitely not a Docker issue because I have tried to check WebSocket connection inside the container (where the regular Ubuntu environment).
Maybe this issue is depending on the method of the launching of rskj. WebSocket server simply not started at all (as it visible from rskj starting log).

Running rskj without a Docker also not helps (((

@tinchou

This comment has been minimized.

Copy link
Contributor

tinchou commented Dec 5, 2018

I just ran your repro on my local node instance and it worked perfectly:

image

When I said "Docker configuration issue", I meant an issue that only happens when you try to run this in a dockerized environment. Port binding gets trickier, and that's why I suggested a simpler test before moving into Docker.

FYI, the node I am using is a mainnet node, and I only had to set rpc.providers.web.ws.enabled=true. Note that the default log configuration might not show the RPC WebSocket enabled message.

@tinchou

This comment has been minimized.

Copy link
Contributor

tinchou commented Dec 5, 2018

  1. try setting rpc.providers.web.ws.bind_address to 0.0.0.0
  2. if that doesn't work, try to make things work before moving into Docker, so we can better diagnose what is happening here. as I just mentioned, your example does work for me.
@Bagaric

This comment has been minimized.

Copy link

Bagaric commented Dec 6, 2018

I get a bit of both with the same setup - first time I run the tester script the connection works (fetches the blockHeader in this example), but every other consecutive connection fails.

@adauto82 adauto82 self-assigned this Dec 6, 2018

@adauto82 adauto82 referenced this issue Dec 10, 2018

Merged

Websocket bug #725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment