Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_SOCKET_BAD_PORT + can not catch error #1607

Closed
flamewow opened this issue Apr 4, 2019 · 4 comments
Closed

ERR_SOCKET_BAD_PORT + can not catch error #1607

flamewow opened this issue Apr 4, 2019 · 4 comments

Comments

@flamewow
Copy link

@flamewow flamewow commented Apr 4, 2019

What version of WebTorrent?
0.103.1
What operating system and Node.js version?
MacOS 10.14.3, nodejs 10.15.1
What browser and version? (if using WebTorrent in the browser)

What did you expect to happen?
download torrent (via magnet link) or handle the error gracefully.
What actually happened?
got error, couldn't catch it in any way. Process crashed.

dgram.js:385
    throw new ERR_SOCKET_BAD_PORT(port);
    ^

RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received 69691337.
    at Socket.send (dgram.js:385:11)
    at send (/Users/ilya/work/voxsync/ctorrent/node_modules/bittorrent-tracker/lib/client/udp-tracker.js:221:12)
    at UDPTracker._request (/Users/ilya/work/voxsync/ctorrent/node_modules/bittorrent-tracker/lib/client/udp-tracker.js:99:3)
    at UDPTracker.announce (/Users/ilya/work/voxsync/ctorrent/node_modules/bittorrent-tracker/lib/client/udp-tracker.js:39:8)
    at /Users/ilya/work/voxsync/ctorrent/node_modules/bittorrent-tracker/client.js:241:13
    at Array.forEach (<anonymous>)
    at Client._announce (/Users/ilya/work/voxsync/ctorrent/node_modules/bittorrent-tracker/client.js:239:18)
    at Client.start (/Users/ilya/work/voxsync/ctorrent/node_modules/bittorrent-tracker/client.js:180:8)
    at Discovery._createTracker (/Users/ilya/work/voxsync/ctorrent/node_modules/torrent-discovery/index.js:158:13)
    at new Discovery (/Users/ilya/work/voxsync/ctorrent/node_modules/torrent-discovery/index.js:63:27)
Waiting for the debugger to disconnect...
@alxhotel

This comment has been minimized.

Copy link
Member

@alxhotel alxhotel commented Apr 5, 2019

You are probably using the number 69691337 as a port for one of the torrent UDP trackers.

The code below to catch the error is working for me:

var Discovery = require("torrent-discovery")

try {
    var discovery = new Discovery({
        infoHash: '6a9759bffd5c0af65319979fb7832189f4f3c35d',
        peerId: 'idyg789dg',
        port: 2008,
        announce: [
            "udp://tracker.coppersurfer.tk:69691337"
        ]
    });
} catch (err) {
    console.log("ERROR: " + err);
}
@flamewow

This comment has been minimized.

Copy link
Author

@flamewow flamewow commented Apr 5, 2019

Hi @alxhotel
I'm passing magnet link as a string:

here is reduced example of the code I used

const WebTorrent = require('webtorrent')
const torrentClient = new WebTorrent()
...
const downloadTorrent = async (magnet) => {
  try {
    const torrentClient = new WebTorrent()
    const torrent = await new Promise((resolve, reject) => {
      torrentClient.add(magnet, torrentOptions, (torrent) => {
        return resolve(torrent)
      })
    })
  } catch (err) {
    console.error('ERROR: ' + err)
  }
}
...

That construction doesn't allow you to catch exceptions, process just crashes.
I'm not using torrent-discovery module.

P.S. I've parsed magnet link with 'magnet-uri' module and found
'udp://tracker.opentrackr.org:69691337/announce" in 'announce' array.
The question is - how to validate/prevent such 'announce' items of breaking nodejs process?

@alxhotel

This comment has been minimized.

Copy link
Member

@alxhotel alxhotel commented Apr 5, 2019

Ah got it. Thanks @flamewow.

I think this is a bug in the bittorrent-tracker package. Those type of errors should be caught and emitted as a warning event. @DiegoRBaquero thoughts ?

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Apr 5, 2019

This case should be handled in the tracker client indeed and just print a warning, ignoring the tracker. Willing to make a PR?

@lock lock bot locked as resolved and limited conversation to collaborators Jul 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.