holochain / n3h

nodejs implementation of holochain networking / p2p backend process
48 stars 7 forks source link

IPC vs P2P race condition error prevents startup #63

Open Connoropolous opened 5 years ago

Connoropolous commented 5 years ago

I am using the n3h server on heroku as a test of holorelay type connections

When using remote wss connection, IPC connects before P2P and starts messaging, but that causes an unhandled error to be thrown and the n3h process to die.

(@hackmode@) [t] Received IPC:  {"method":"requestState"}
Strict Fail on Unhandled Promise Rejection
TypeError: Cannot read property 'getId' of undefined
    at N3hHackMode._handleIpcJson (/Users/connor/code/holochain/n3h/lib/hackmode/index.js:153:25)

I was able to confirm that this same error does NOT occur if you just launch n3h from outside the conductor, just manually, because no IPC communications start to occur.

In my initial testing, I've found that adding the following to the top of _handleIpcJson prevents the process from dying, but networking still doesn't work afterwards. Seeing no gossip between nodes

    if (!this._p2p) {
      return
    }

I have this config in my conductor-config.toml file

[network]
n3h_path = "/Users/connor/code/holochain/n3h"
n3h_log_level = "t"
n3h_persistence_path = "/tmp"
bootstrap_nodes = []
networking_config_file = "./network_config.json"

and my network_config.json file looks like this:

{
    "webproxy": {
        "connection": {
            "rsaBits": 1024,
            "bind": [
                "wss://0.0.0.0:0/"
            ]
        },
        "wssRelayPeers": ["wss://n3hserver.herokuapp.com/?a=hkYcCLPsTGt_O4hxyQRC1tCdjxI7PbSSPbQ7mAE1cpTuAdvQLmNdqJuB0gjhdijiLpSXkwvrqSijMknrDev0q_UvCSELUDGM"]
    }
}
$ holochain -c ./conductor-config.toml
Using config path: ./conductor-config.toml
Unlocking agent keys:
Unlocking key for agent 'test_agent1':
Reading agent key from /Users/connor/Library/Preferences/org.holochain.holochain/keys/HcSCi3kn9pBWtgt4cpc3eXEKZSzw5x83bZMgxyPSxky36czhpAwcJt6I9ebg5gz
Passphrase:
Spawning network with working directory: /tmp
(n3h-bin) [w] attempting read stdin
(n3h-bin) [w] got stdin config! {"webproxy":{"connection":{"rsaBits":1024,"bind":["wss://0.0.0.0:0/"]},"wssRelayPeers":["wss://n3hserver.herokuapp.com/?a=hkYcCLPsTGt_O4hxyQRC1tCdjxI7PbSSPbQ7mAE1cpTuAdvQLmNdqJuB0gjhdijiLpSXkwvrqSijMknrDev0q_UvCSELUDGM"]}}
(n3h-bin) [i] executing mode HACK
(*n3hMode*) [i] @@ CONFIG @@ {
  "ipc": {
    "connection": {
      "rsaBits": 1024,
      "bind": [
        "wss://127.0.0.1:0/"
      ]
    }
  },
  "webproxy": {
    "connection": {
      "rsaBits": 1024,
      "bind": [
        "wss://0.0.0.0:0/"
      ]
    },
    "wssAdvertise": "auto",
    "wssRelayPeers": [
      "wss://n3hserver.herokuapp.com/?a=hkYcCLPsTGt_O4hxyQRC1tCdjxI7PbSSPbQ7mAE1cpTuAdvQLmNdqJuB0gjhdijiLpSXkwvrqSijMknrDev0q_UvCSELUDGM"
    ]
  }
}
(wss-server-utils) [i] loaded rsa fingerprint fyzdZseJKgmMoNjPOZzycUBW+a8=
(wss-connection) [i] listening at wss://127.0.0.1:54525/
(*n3hMode*) [t] bound to wss://127.0.0.1:54525/
Network spawned with bindings:
     - ipc: wss://127.0.0.1:54525/
     - p2p: []
Reading DNA from dna/holo-chat.hcpkg
(p2p-hackmode) [i] node-id hkbVrAOxyF_4K-VPxI87oHnhp64YEWdIOtK_uFBVs6kt06hMRThqOrdyFIZdrjGw1tScpkHPv-20jclqu0BuOscbWvbU8X5a
(wss-server-utils) [i] loaded rsa fingerprint fyzdZseJKgmMoNjPOZzycUBW+a8=
(wss-connection) [i] listening at wss://192.168.1.9:54526/
(@hackmode@) [t] Received IPC:  {"method":"requestState"}
Strict Fail on Unhandled Promise Rejection
TypeError: Cannot read property 'getId' of undefined
    at N3hHackMode._handleIpcJson (/Users/connor/code/holochain/n3h/lib/hackmode/index.js:153:25)
    at N3hHackMode._handleIpcEvent (/Users/connor/code/holochain/n3h/lib/n3h-ipc/n3hMode.js:150:18)
    at _ipc.on.ev (/Users/connor/code/holochain/n3h/lib/n3h-ipc/n3hMode.js:87:38)
    at Promise.all._events.(anonymous function).map.fn (/Users/connor/code/holochain/n3h/lib/n3h-common/async-class.js:129:14)
    at Array.map (<anonymous>)
    at Connection.emit (/Users/connor/code/holochain/n3h/lib/n3h-common/async-class.js:128:43)
    at Connection.$emitEvent (/Users/connor/code/holochain/n3h/lib/n3h-mod-spec/connection-spec.js:239:17)
    at WebSocket.ws.on (/Users/connor/code/holochain/n3h/lib/n3h-mod-connection-wss/wss-connection.js:261:24)
    at emitOne (events.js:116:13)
    at WebSocket.emit (events.js:211:7)
Error occured in p2p network module, on tick: TransportError("Os { code: 61, kind: ConnectionRefused, message: \"Connection refused\" }")
Successfully loaded instance holo-chat from storage
adding ui interface ui-interface
Successfully loaded 1 instance configurations
Starting all of them...
Starting instance "holo-chat"...
Starting interfaces...
Done.
Starting UI servers
Starting all servers
About to serve path "./ui" at http://127.0.0.1:3000
Server started for "ui-interface"
Listening on http://127.0.0.1:3000
neonphog commented 5 years ago

@Connoropolous - this was resolved, yes?

Connoropolous commented 5 years ago

I would have to go back and check, based on all the work that's happened since. I haven't seen mention of anything that I specifically thought addressed this though...