Skip to content

Commit

Permalink
Add steps to reproduce issue Bitcoin-com#173 showing redundant connec…
Browse files Browse the repository at this point in the history
…tions.
  • Loading branch information
rnbrady committed Feb 10, 2020
1 parent 6e70545 commit 267b2e3
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/e2e/count-connections-issue-173/countConnectionsBitSocket.js
@@ -0,0 +1,57 @@
const BITBOX = require("../../../lib/BITBOX").BITBOX;
const { exec } = require('child_process');

const bitbox = new BITBOX();
const socket = new bitbox.Socket();

function countSockets(stage) {
return new Promise((resolve, reject) => {
// Call the lsof system command for outgoing internet connections.
exec(`lsof -i -n -P | grep ${process.pid}`, (err, stdout, stderr) => {
// Print list of open connections allowing a visual count to be done.
console.log(`Outbound connections from this node process ${stage}:\n${stdout}`);
resolve();
});
});
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

(async () => {

await countSockets("before calling listen");

//First call to listen() which should create new connection.
socket.listen({"v": 3, "q": {"find": {}}},
(message) => {
console.log("Callback from first query invoked.");
});

//Second call to listen() which should share connection with first call.
socket.listen({"v": 3, "q": {"find": {}}},
(message) => {
console.log("Callback from first query invoked.");
});

// listen doesn't return a promise so wait 100ms for connections to establish.
await sleep(100);

await countSockets("after calling listen twice");

// now close the socket
socket.close();

// callback from close() is short-circuited so give it 100ms to clean up.
await sleep(100);

// check if any zombie connections remaining
await countSockets("after calling close (zombie connections)");

// exit process
process.exit();

})();


55 changes: 55 additions & 0 deletions test/e2e/count-connections-issue-173/countConnectionsSocketIO.js
@@ -0,0 +1,55 @@
const BITBOX = require("../../../lib/BITBOX").BITBOX;
const { exec } = require('child_process');

const bitbox = new BITBOX();
const socket = new bitbox.Socket();

function countSockets(stage) {
return new Promise((resolve, reject) => {
// Call the lsof system command for outgoing internet connections.
exec(`lsof -i -n -P | grep ${process.pid}`, (err, stdout, stderr) => {
// Print list of open connections allowing a visual count to be done.
console.log(`Outbound connections from this node process ${stage}:\n${stdout}`);
resolve();
});
});
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

(async () => {

await countSockets("before calling listen");

//First call to listen() which should create new connection.
socket.listen("transactions", (message) => {
console.log("Received a transaction.");
});

//Second call to listen() which should share connection with first call.
socket.listen("blocks", (message) => {
console.log("Received a block.");
});

// listen doesn't return a promise so wait 100ms for connections to establish.
await sleep(100);

await countSockets("after calling listen twice");

// now close the socket
socket.close();

// callback from close() is short-circuited so give it 100ms to clean up.
await sleep(100);

// check if any zombie connections remaining
await countSockets("after calling close (zombie connections)");

// exit process
process.exit();

})();


0 comments on commit 267b2e3

Please sign in to comment.