-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(@embark/utils): use timeouts to improve utils.pingEndpoint
For reasons unknown, sockets underlying http and websocket requests made by `utils.pingEndpoint` could become stuck and after a *long* time eventually hang up. This can happen even when the endpoint being ping'd is perfectly responsive, e.g. when checking it with `curl` in another terminal. The root cause may be a bug in node.js itself or some package upon which embark depends. The effects of the stuck sockets are experienced more often when the CPU is under moderate-heavy load. Use timeouts to cut short the stuck sockets. Usually, after one-to-several retries (which may get stuck) following a stuck socket, connections behave as expected (learned by experience). It's not enough to rely on the http/websocket built-in timeouts, since when the CPU is busy those timeouts fail to fire reliably (learned by experience). By overlapping the built-in timeouts with `setTimeout`, `pingEndpoint` avoids becoming stuck; it's also important to use `setImmediate` to defer some calls and socket cleanups (learned by trial and error). Note that when the CPU is moderately busy, one of the slowest steps is launching embark's child processes, e.g. ipfs, geth, etc. However, even under very heavy load, with the revised `pingEndpoint` embark seems to always eventually start/detect services correctly. And under light to moderate load, the effect of the stuck sockets is less noticeable. Use a weboscket client from the `ws` package instead of manually building websocket headers. Use `pingEndpoint` for the IPFS module's `_checkService` method to avoid the same stuck socket problem that was affecting blockchain detection.
- Loading branch information
1 parent
72f8701
commit 1f955bd
Showing
3 changed files
with
128 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters