Created
May 7, 2017 19:59
-
-
Save eriktrom/c1625e6c41e796f76422dcebbc3039c6 to your computer and use it in GitHub Desktop.
portfinder-manual-test-diff-from-ember-cli-ember-s-wip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var net = require('net'); | |
var portfinder = require('portfinder'); | |
// console.log(process.env); | |
portfinder.getPort({ port: 58886 }, function (err, port) { | |
if (err) { | |
throw err; | |
} | |
console.log(port); | |
}); | |
// var server = http.createServer(function (err) { | |
// if (err) { | |
// throw err; | |
// } | |
// console.log('hi'); | |
// }); | |
// server.listen({ port: 5886, host: '::1' }); | |
// server.on('listen', function() { | |
// console.log('is listening'); | |
// }) | |
// server.on('error', function(err) { | |
// console.log('err', err); | |
// }) | |
const hosts = [ '127.0.0.1', '::1', 'fe80::1', 'fe80::188f:e1d0:3d8e:7de5', '192.168.0.55', 'fe80::68f8:2fff:fed3:2b75', 'fe80::ef2a:6826:dc6e:eb21', 'fe80::e47:7e46:1d67:7093', 'fe80::6a85:4c16:fbdb:3da5', 'fe80::fe5a:ff06:9900:8c8d', 'fe80::c41f:4f23:93ae:b77c', 'fe80::aede:48ff:fe00:1122' ]; | |
hosts.forEach(host => { | |
const server = net.createServer((socket) => { | |
socket.end('goodbye\n'); | |
}).on('error', (err) => { | |
// handle errors here | |
console.log('Failed', err); | |
process.exitCode = 1 | |
}); | |
// grab a random port. | |
server.listen({ port: 5886, host }, () => { | |
console.log('opened server on', server.address()); | |
process.exitCode = 0; | |
server.close(); | |
}); | |
server.on('close', (...rest) => { | |
console.log('server is closed', ...rest); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very bad notes, will make this more clear soon, dropping whats in brain(recalled)
where
fe80::*
is touchbar host and port5886
can be found as the touchbar port by usingsudo lsof -i
then playing with the touchbar - when you see[xxx]:y-->[fe80:zzz]:61000
you have found the pid being used by touchbar (note the6100
) - u can kill this process, and watch it restart by again playing with touchbar - if u npm link everything correctly, and plug this number in as the basePort in commands/serve.js, u can duplicate the failure deterministically.main takeaway here that you'd find (if u manually go through all of this, including updating the script above w/ correct port) is that touchbar will actually allow starting a server on that port, but will fail when serving a file (IIRC - the livereload.js file) through
ember s
, due to a permissions error. this means to accurately test if a port and host are usable, we have to update portfinder to serve a file, and then assert that serving the file does not throw - an echo client/server pair that pipes text through is not sufficient which is the current logic in the branch http-party/node-portfinder#53 needs to implement this updatealso note, that using
os.networkInterfaces()
will put the touchbar host at the end of the above list, we moved it to the beginning - which revealed that the sudo error when starting the server is coming from a different host/interface, somewhere in between192.168.0.55
and end of host list in above script !important!these notes are not fully complete nor accurate, as they come from my brain, after a debugging session, very late at night, after some some beers >= 5 days ago.
however, they are worth dropping, and i'll update this gist with a more complete/accurate explanation after the next pairing session we have.