This PR replaces #1166. The "stuck sockets" bug is addressed in #1195 so there
is no longer a need to use timeouts. However a few aspects of the original PR
are still useful, and lessons learned from #1166, #1181, and #1195 can be put
to good use.
Use a websocket client from the `ws` package when pinging websocket endpoints
instead of manually building a request header. The `'upgrade'` event being
listened for was never actually firing; and though a response was received for
those pings, the response messages indicated problems with those requests. It
seems cleaner to use a proper websocket client and callback success upon the
`ws` client's `'open'` event.
Abstract error and success handling across websocket and http pings.
Report network errors other than `ECONNREFUSED`. Only `ECONNREFUSED` is
expected, as that genuinely indicates an endpoint isn't accepting connections
at the specified host and port. If other kinds of network errors are occurring,
it will be helpful to have a visual indicator to prompt investigation.
After success or the first error, cleanup the ping's request/connection
immediately since we're not awaiting `'data'` events on an http request and we
don't want to leave a websocket connection open. Don't callback any `'error'`
events that might fire after the first `'error'` event or a success event, but
do report them.
The problems described in embark PR #1166 can be resolved by implementing the
blockchain proxy with `http-proxy` directly instead of using `express` together
with `http-proxy-middleware`. The ultimate cause of the buggy behavior (the
"stuck sockets" problems described in #1166) is unknown.
The need to swallow some errors as described in embark PR #1181 is also
eliminated by dropping `http-proxy-middleware` and `express`.
In 1461e95c39 we've introduced a guard that ensures whisper isn't crashing
when Embark is used with the Simulator. This unfortunately also introduced
code that tries to connect to an existing websocket provider that isn't actually
ready at the time it tries to connect.
This commit ensures `web3.shh.getInfo()` is only called once `web3` is ready
and therefore the WS connection as well.
For reasons unknown, `ECONNRESET` errors on websocket connections to embark's
blockchain proxy are not automatically handled on Windows as they are on macOS
and Linux (or those errors aren't happening on those platforms, it's difficult
to determine). Explicitly swallow such errors so the blockchain process doesn't
crash. Prior to this PR, the crash-behavior can be reproduced on Windows by
running `embark blockchain` and `embark run` in separate terminals and quitting
`embark run` while `embark blockchain` is still running.
Consistently use the `simples` package's `WsParser` to process websocket
traffic instead of using `WsParser` for requests and the `ws` package's
`Websocket.Receiver` for responses.
Consistently use `pump` to connect parser streams instead of using `pump` in
some places and `chain` in others. Drop use of `cloneable` (and the package
dependency) since it was used previously in hopes it would fix the errors, but
it's unnecessary and didn't fix them.
Prior to this commit, it wasn't possible to enter decimal numbers
with dots. The reason for that is that all units are recalculated
on form control change and values like `2.` are simply converted to
`2`.
As every change will cause a `setState()` in Cockpit, users never had
a chance to get "beyond" the first dot of their input value.
This is now fixed by preventing the recalculation all together when
the last character in the entered value is a `.`
In that case, we simply update the form control using `setState()` and
don't touch all the other values. The next key stroke will cause a full
recalculation again.