friedrith / node-wifi

📶 NodeJS tool to manage wifi (connections, scans)
MIT License
397 stars 161 forks source link

Parser bombs on Windows 7 #20

Closed lordbah closed 6 years ago

lordbah commented 6 years ago

Frequently on a Windows 7 system the scan method bombs the node.exe process. The netsh output gets truncated (reason unknown), from what I've seen always after the Encryption line for some network. The parser then chokes

...\node_modules\node-wifi\src\windows-scan.js:66
        var channelLine = networkTmp[7].split(' ').join('').split(':');
                                       ^

TypeError: Cannot read property 'split' of undefined
    at parse (...\node_modules\node-wifi\src\window
s-scan.js:66:33)
    at ...\node_modules\node-wifi\src\windows-scan.
js:41:15
    at ChildProcess.exithandler (child_process.js:262:7)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at maybeClose (internal/child_process.js:927:16)
    at Socket.stream.socket.on (internal/child_process.js:348:11)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at Pipe._handle.close [as _onclose] (net.js:545:12)

To avoid the crash I had to edit windows-scan.js and inside scanWifi() put a try/catch around most of the work, have the catch set err, and send err in the final callback instead of null (in a successful parse, the value of err is null). I could not find any way to catch this error with the released code.

Then in my callback if err is set I sleep for 20 seconds and call scan again, and it works.

friedrith commented 6 years ago

This behavior never happened to me but hardware-dependent programs are not very determinist. I have planned to rework a significant part of the library tomorrow to take account of another user needs so I will add the try/catch.

Thx for your advice and do not hesitate to propose other improvements.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.