Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fixed ports.free() bug when passed just a number #14

Merged
merged 1 commit into from

2 participants

@mbrevoort

When calling free explicitly from a seaport client, if you just pass the port as a number parameter the params._id (which I introduced) value is undefined and the role wasn't getting properly deallocated.

@substack substack merged commit 36f7b04 into substack:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 21, 2012
  1. @mbrevoort
This page is out of date. Refresh to see the latest.
Showing with 41 additions and 1 deletion.
  1. +3 −1 index.js
  2. +38 −0 test/free_port.js
View
4 index.js
@@ -302,7 +302,9 @@ exports.createServer = function (opts) {
Object.keys(roles).forEach(function (role) {
var rs = roles[role];
roles[role] = rs.filter(function (r) {
- var x = r.port === port && r.host === host && r._id === id;
+ // if no id passed into free, don't consider it
+ var idCondition = (!id || r._id === id);
+ var x = r.port === port && r.host === host && idCondition;
if (x) {
var ix = allocated.indexOf(r);
if (ix >= 0) allocated.splice(ix, 1);
View
38 test/free_port.js
@@ -0,0 +1,38 @@
+var test = require('tap').test;
+var seaport = require('../');
+
+// same exact test as free.js but passing ports.free a number parameter
+test('free', function (t) {
+ t.plan(6);
+ var port = Math.floor(Math.random() * 5e4 + 1e4);
+ var server = seaport.createServer();
+ server.listen(port);
+
+ var ports = seaport.connect('localhost', port);
+ var gotPort, gotRec;
+ server.on('free', function (rec) {
+ t.same(rec, gotRec);
+ t.same(server.allocated[gotRec.host], []);
+ ports.close();
+ });
+
+ ports.allocate('http', function (p) {
+ t.ok(p >= 10000 && p < 65536);
+ gotPort = p;
+
+ process.nextTick(function () {
+ ports.query('http', function (ps) {
+ t.equal(ps.length, 1);
+ t.equal(ps[0].host, '127.0.0.1');
+ t.equal(ps[0].port, gotPort);
+
+ gotRec = ps[0];
+ ports.free(ps[0].port);
+ });
+ });
+ });
+
+ t.on('end', function () {
+ server.close();
+ });
+});
Something went wrong with that request. Please try again.