alxhotel / nat-api

:left_right_arrow: Fast port mapping with UPnP and NAT-PMP
MIT License
23 stars 13 forks source link

autoUpdate causes unhandled errors #24

Closed achingbrain closed 3 years ago

achingbrain commented 3 years ago

If you enable autoUpdate, it'll set an interval to perform the update.

Problem is, it creates a bound function without a callback, then executes the callback assuming it has a value, so your process will crash:

events.js:292
      throw er; // Unhandled 'error' event
      ^

TypeError: cb is not a function
    at /Users/alex/test/dht/node_modules/@motrix/nat-api/index.js:336:7
    at /Users/alex/test/dht/node_modules/@motrix/nat-api/lib/upnp/device.js:61:11
    at Parser.<anonymous> (/Users/alex/test/dht/node_modules/xml2js/lib/parser.js:304:18)
    at Parser.emit (events.js:315:20)
    at SAXParser.onclosetag (/Users/alex/test/dht/node_modules/xml2js/lib/parser.js:262:26)
    at emit (/Users/alex/test/dht/node_modules/sax/lib/sax.js:624:35)
    at emitNode (/Users/alex/test/dht/node_modules/sax/lib/sax.js:629:5)
    at closeTag (/Users/alex/test/dht/node_modules/sax/lib/sax.js:889:7)
    at SAXParser.write (/Users/alex/test/dht/node_modules/sax/lib/sax.js:1436:13)
    at Parser.exports.Parser.Parser.parseString (/Users/alex/test/dht/node_modules/xml2js/lib/parser.js:323:31)
achingbrain commented 3 years ago

Looks like the same bug is here as well.

I've opened a PR with a fix - #25