I get a 'connection not open on send()' error immediately after connecting to a Websocket for a Kaleido node. I am trying to use the WebsocketProvider from web3js version 1.0.0-beta.34.
My code for the connection looks like this, where username
, password
and wssUrl
are local variables with the information about the Kaleido node.
const web3 = new Web3(new Web3.providers.WebsocketProvider(`wss://${username}:${password}@${wssUrl}`))
I've tried the suggested steps listed in this Github issue -- trying to reconnect if the connection is lost, but the error still persists. I think it may be a Kaleido issue as I'm able to use the WebsocketProvider for a local Ganache account.
It would be helpful to be able to use the Websocket connection for a Kaleido node, so I can use web3js version 1.0. The HTTP connection works just fine, but in web3js 1.0 listening for events with the HttpProvider is deprecated, thus forcing you to use the WebsocketProvider. Thanks!
web3js 1.0.0-beta.34 will fallback to Node JS's legacy URL parser. Changes have already been delivered to the 1.0 branch of ethereum/web3.js to remedy this issue.
To work around this:
npm i -g lerna
npm i https://github.com/ethereum/web3.js.git\#1.0
lerna is just a build tool that the web3 project relies on during development.
I just watched the Wireshark log for this request and it seems web3js is not passing the basic Authn headers during the WebSocket upgrade request.
GET / HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: XXXX==
Host: zzzzz-zzzzz-wss.us-east-2.kaleido.io
One might, think that Sec-WebSocket-Key is an Authn header, but it's really a protocol countermeasure for another sort of attack. You can read more at this quesiton: What is Sec-WebSocket-Key for?
I'll take a look and see if I can hack together a patch to get this working.