ssbc / ssb-lan

SSB plugin for discovery of other peers in the same LAN
MIT License
7 stars 1 forks source link

Cannot read property 'close' of null #5

Closed christianbundy closed 4 years ago

christianbundy commented 4 years ago

Hi @staltz! I'm writing some small functionality for Oasis so that people can start/stop/restart their network activity from the CLI, but I'm bumping into a small error.

I don't know how to tell whether SSB-CONN is active, so I never know whether I should show the 'start' or 'stop' buttons. This means that I'm showing both buttons, but if you hit 'stop' twice then SSB-LAN throws this error:

Error: non-error thrown: {"message":"Cannot read property 'close' of null","name":"TypeError","stack":"TypeError: Cannot read property 'close' of null\n    at Object.LAN.stop (/home/christianbundy/src/fraction/oasis/node_modules/ssb-lan/lib/index.js:83:35)\n    at Object.<anonymous> (/home/christianbundy/src/fraction/oasis/node_modules/secret-stack/util.js:80:17)\n    at Object.<anonymous> (/home/christianbundy/src/fraction/oasis/node_modules/hoox/index.js:3:17)\n    at Object.hooked [as stop] (/home/christianbundy/src/fraction/oasis/node_modules/hoox/index.js:10:15)\n    at Object.ConnScheduler.stop (/home/christianbundy/src/fraction/oasis/node_modules/ssb-conn/lib/conn-scheduler.js:134:132)\n    at Object.<anonymous> (/home/christianbundy/src/fraction/oasis/node_modules/secret-stack/util.js:80:17)\n    at Object.<anonymous> (/home/christianbundy/src/fraction/oasis/node_modules/hoox/index.js:3:17)\n    at Object.hooked [as stop] (/home/christianbundy/src/fraction/oasis/node_modules/hoox/index.js:10:15)\n    at CONN.stopScheduler (/home/christianbundy/src/fraction/oasis/node_modules/ssb-conn/lib/conn.js:145:36)\n    at Object.CONN.stop (/home/christianbundy/src/fraction/oasis/node_modules/ssb-conn/lib/conn.js:66:18)"}
    at Object.onerror (/home/christianbundy/src/fraction/oasis/node_modules/koa/lib/context.js:113:40)
    at onerror (/home/christianbundy/src/fraction/oasis/node_modules/koa/lib/application.js:163:32)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)

Here are the versions being used:

@fraction/oasis@2.11.0 /home/christianbundy/src/fraction/oasis
└─┬ @fraction/flotilla@3.0.1
  ├── ssb-conn@0.15.1 
  ├── ssb-lan@0.2.0 
  └─┬ ssb-room@1.2.0
    └── ssb-conn@0.15.1  deduped
christianbundy commented 4 years ago

Got an error stack that's less ugly:

Error [TypeError]: Cannot read property 'close' of null
    at Object.LAN.stop (/home/christianbundy/src/fraction/oasis/node_modules/ssb-lan/lib/index.js:83:35)
    at Object.<anonymous> (/home/christianbundy/src/fraction/oasis/node_modules/secret-stack/util.js:80:17)
    at Object.<anonymous> (/home/christianbundy/src/fraction/oasis/node_modules/hoox/index.js:3:17)
    at Object.hooked [as stop] (/home/christianbundy/src/fraction/oasis/node_modules/hoox/index.js:10:15)
    at Object.ConnScheduler.stop (/home/christianbundy/src/fraction/oasis/node_modules/ssb-conn/lib/conn-scheduler.js:134:132)
    at Object.<anonymous> (/home/christianbundy/src/fraction/oasis/node_modules/secret-stack/util.js:80:17)
    at Object.<anonymous> (/home/christianbundy/src/fraction/oasis/node_modules/hoox/index.js:3:17)
    at Object.hooked [as stop] (/home/christianbundy/src/fraction/oasis/node_modules/hoox/index.js:10:15)
    at CONN.stopScheduler (/home/christianbundy/src/fraction/oasis/node_modules/ssb-conn/lib/conn.js:145:36)
    at Object.CONN.stop (/home/christianbundy/src/fraction/oasis/node_modules/ssb-conn/lib/conn.js:66:18)
staltz commented 4 years ago

Thanks for letting me know @christianbundy

First suspicion: are you absolutely sure that you have ssb-lan@0.2.0 and ssb-conn@0.15.1? Because the line numbers mentioned in the stack trace don't quite match with the lib/*.js files I have for those versions.

Further, the only use of close() in ssb-lan is now guarded by an if which should certainly protect us from Cannot read property 'close' of null:

if (this.normalBroadcast) {
 this.normalBroadcast.close();
 this.normalBroadcast = void 0;
}
if (this.legacyBroadcast) {
  this.legacyBroadcast.close();
  this.legacyBroadcast = void 0;
}

In ssb-lan@0.1.4, it didn't use to have those null checks, so I suspect you have 0.1.4

I don't know how to tell whether SSB-CONN is active

This would be a good API to have!

christianbundy commented 4 years ago

Oops, my code was updated to the latest versions but I was connecting to a server over MuxRPC that was using the older SSB-CONN. :man_facepalming: