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

Follow promises across resolve #40

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[**]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
trim_trailing_whitespace = true
indent_size = 2
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"no-new-func": 0,
"prefer-const": 1,
"no-var": 1
}
},
"extends": [
"eslint:recommended"
]
}
59 changes: 59 additions & 0 deletions debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

// We cannot use console.log for debugging because it would call back into our hook
const fs = require('fs');
function debug(msg) {
fs.writeSync(1, 'trace.js DEBUG ' + msg + '\n');
}

function printRootTraces(traces) {
const rootAsyncIds = findRootAsyncIds(traces);
for (const asyncId of rootAsyncIds) {
printTree(traces, traces.get(asyncId));
}
}

function findRootAsyncIds(traces) {
const asyncIds = new Set(traces.keys());
for (const trace of traces.values()) {
for (const notRootTrace of trace.relatedTraces) {
asyncIds.delete(notRootTrace.asyncId);
}
}
return asyncIds;
}

function printTree(traces, trace, indent='', isLast=true, visited=new Set()) {
let line = indent + '\\-' + trace.asyncId;

if (isLast) {
indent += ' ';
} else {
indent += '| ';
}

if (!traces.get(trace.asyncId)) {
line += ' (not-root)';
}

if (visited.has(trace.asyncId)) {
line += ' (cycle)';
}

fs.writeSync(1, line + '\n');

if (visited.has(trace.asyncId)) {
return;
}
visited.add(trace.asyncId);

for (let i = 0; i < trace.relatedTraces.length; ++i) {
const isLast = i === trace.relatedTraces.length - 1;
printTree(traces, trace.relatedTraces[i], indent, isLast, visited);
}
}

module.exports = {
debug,
printRootTraces
};
29 changes: 29 additions & 0 deletions test/expected/async-await-follow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Error: FAIL
at f1 (/scripts/async-await-follow.js:3:9)
at ____________________:0:0
at ____________________:0:0
at f1.<anonymous> (<anonymous>)
at f1 (/scripts/async-await-follow.js:2:17)
at ____________________:0:0
at <anonymous>
at f1 (/scripts/async-await-follow.js:1:80)
at f2 (/scripts/async-await-follow.js:8:9)
at ____________________:0:0
at ____________________:0:0
at ____________________:0:0
at ____________________:0:0
at f2.<anonymous> (<anonymous>)
at f2 (/scripts/async-await-follow.js:7:17)
at ____________________:0:0
at <anonymous>
at f2 (/scripts/async-await-follow.js:6:18)
at f3 (/scripts/async-await-follow.js:14:11)
at <anonymous>
at ____________________:0:0
at ____________________:0:0
at f3.<anonymous> (<anonymous>)
at f3 (/scripts/async-await-follow.js:12:17)
at ____________________:0:0
at <anonymous>
at f3 (/scripts/async-await-follow.js:11:18)
at Object.<anonymous> (/scripts/async-await-follow.js:20:1)
22 changes: 5 additions & 17 deletions test/expected/promise-child-stack.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
Error: hello
at scopeThrow (/scripts/promise-child-stack.js:r:c)
at scopeThrow (/scripts/promise-child-stack.js:5:17)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:r:c)
at Function.Module.runMain (module.js:r:c)
at startup (bootstrap_node.js:r:c)
at bootstrap_node.js:r:c
at PromiseWrap.emitInitNative (internal/async_hooks.js:r:c)
at ____________________:0:0
at Promise.then (<anonymous>)
at Object.<anonymous> (/scripts/promise-child-stack.js:r:c)
at PromiseWrap.emitInitNative (internal/async_hooks.js:r:c)
at Object.<anonymous> (/scripts/promise-child-stack.js:4:15)
at ____________________:0:0
at Function.resolve (<anonymous>)
at Object.<anonymous> (/scripts/promise-child-stack.js:r:c)
at Module._compile (module.js:r:c)
at Object.Module._extensions..js (module.js:r:c)
at Module.load (module.js:r:c)
at tryModuleLoad (module.js:r:c)
at Function.Module._load (module.js:r:c)
at Function.Module.runMain (module.js:r:c)
at startup (bootstrap_node.js:r:c)
at bootstrap_node.js:r:c
at Object.<anonymous> (/scripts/promise-child-stack.js:3:20)
21 changes: 21 additions & 0 deletions test/expected/promise-resolve-follow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Error: FAIL
at Timeout.setTimeout [as _onTimeout] (/scripts/promise-resolve-follow.js:4:14)
at ____________________:0:0
at new Promise (<anonymous>)
at f1 (/scripts/promise-resolve-follow.js:2:10)
at Promise (/scripts/promise-resolve-follow.js:11:5)
at ____________________:0:0
at new Promise (<anonymous>)
at f2 (/scripts/promise-resolve-follow.js:10:10)
at Promise.resolve.then (/scripts/promise-resolve-follow.js:17:17)
at <anonymous>
at ____________________:0:0
at Promise.catch (<anonymous>)
at f3 (/scripts/promise-resolve-follow.js:18:11)
at ____________________:0:0
at Promise.then (<anonymous>)
at f3 (/scripts/promise-resolve-follow.js:17:6)
at ____________________:0:0
at Function.resolve (<anonymous>)
at f3 (/scripts/promise-resolve-follow.js:16:18)
at Object.<anonymous> (/scripts/promise-resolve-follow.js:21:1)
10 changes: 1 addition & 9 deletions test/expected/regression-delayed-formater.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,4 @@ throw new Error('trace');
^

Error: trace
at-hack Object.<anonymous> (/scripts/regression-delayed-formater.js:r:c)
at-hack Module._compile (module.js:r:c)
at-hack Object.Module._extensions..js (module.js:r:c)
at-hack Module.load (module.js:r:c)
at-hack tryModuleLoad (module.js:r:c)
at-hack Function.Module._load (module.js:r:c)
at-hack Function.Module.runMain (module.js:r:c)
at-hack startup (bootstrap_node.js:r:c)
at-hack bootstrap_node.js:r:c
at-hack Object.<anonymous> (/scripts/regression-delayed-formater.js:17:7)
101 changes: 13 additions & 88 deletions test/expected/regression-http-close.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,16 @@
^

Error: trace
at Server.close (/scripts/regression-http-close.js:r:c)
at Object.onceWrapper (events.js:r:c)
at Server.emit (events.js:r:c)
at emitCloseNT (net.js:r:c)
at process._tickCallback (internal/process/next_tick.js:r:c)
at emitInitNative (internal/async_hooks.js:r:c)
at emitInitScript (internal/async_hooks.js:r:c)
at new TickObject (internal/process/next_tick.js:r:c)
at internalNextTick (internal/process/next_tick.js:r:c)
at Server._emitCloseIfDrained (net.js:r:c)
at Server.close (net.js:r:c)
at IncomingMessage.end (/scripts/regression-http-close.js:r:c)
at Object.onceWrapper (events.js:r:c)
at IncomingMessage.emit (events.js:r:c)
at endReadableNT (_stream_readable.js:r:c)
at process._tickCallback (internal/process/next_tick.js:r:c)
at emitInitNative (internal/async_hooks.js:r:c)
at emitInitScript (internal/async_hooks.js:r:c)
at new TickObject (internal/process/next_tick.js:r:c)
at process.nextTick (internal/process/next_tick.js:r:c)
at endReadable (_stream_readable.js:r:c)
at IncomingMessage.Readable.read (_stream_readable.js:r:c)
at flow (_stream_readable.js:r:c)
at resume_ (_stream_readable.js:r:c)
at process._tickCallback (internal/process/next_tick.js:r:c)
at emitInitNative (internal/async_hooks.js:r:c)
at emitInitScript (internal/async_hooks.js:r:c)
at new TickObject (internal/process/next_tick.js:r:c)
at process.nextTick (internal/process/next_tick.js:r:c)
at resume (_stream_readable.js:r:c)
at IncomingMessage.Readable.resume (_stream_readable.js:r:c)
at IncomingMessage.Readable.on (_stream_readable.js:r:c)
at ClientRequest.get (/scripts/regression-http-close.js:r:c)
at Object.onceWrapper (events.js:r:c)
at ClientRequest.emit (events.js:r:c)
at HTTPParser.parserOnIncomingClient (_http_client.js:r:c)
at HTTPParser.parserOnHeadersComplete (_http_common.js:r:c)
at Socket.socketOnData (_http_client.js:r:c)
at Socket.emit (events.js:r:c)
at addChunk (_stream_readable.js:r:c)
at readableAddChunk (_stream_readable.js:r:c)
at Socket.Readable.push (_stream_readable.js:r:c)
at TCP.onread (net.js:r:c)
at HTTPParser.emitInitNative (internal/async_hooks.js:r:c)
at tickOnSocket (_http_client.js:r:c)
at onSocketNT (_http_client.js:r:c)
at process._tickCallback (internal/process/next_tick.js:r:c)
at emitInitNative (internal/async_hooks.js:r:c)
at emitInitScript (internal/async_hooks.js:r:c)
at new TickObject (internal/process/next_tick.js:r:c)
at process.nextTick (internal/process/next_tick.js:r:c)
at ClientRequest.onSocket (_http_client.js:r:c)
at handleSocketCreation_Inner (_http_agent.js:r:c)
at oncreate (_http_agent.js:r:c)
at Agent.createSocket (_http_agent.js:r:c)
at Agent.addRequest (_http_agent.js:r:c)
at new ClientRequest (_http_client.js:r:c)
at request (http.js:r:c)
at Object.get (http.js:r:c)
at Server.listen (/scripts/regression-http-close.js:r:c)
at Object.onceWrapper (events.js:r:c)
at Server.emit (events.js:r:c)
at emitListeningNT (net.js:r:c)
at process._tickCallback (internal/process/next_tick.js:r:c)
at emitInitNative (internal/async_hooks.js:r:c)
at emitInitScript (internal/async_hooks.js:r:c)
at new TickObject (internal/process/next_tick.js:r:c)
at internalNextTick (internal/process/next_tick.js:r:c)
at Server.setupListenHandle [as _listen2] (net.js:r:c)
at TCP.emitInitNative (internal/async_hooks.js:r:c)
at createServerHandle (net.js:r:c)
at Server.setupListenHandle [as _listen2] (net.js:r:c)
at listenInCluster (net.js:r:c)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:r:c)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:r:c)
at GetAddrInfoReqWrap.emitInitNative (internal/async_hooks.js:r:c)
at Object.lookup (dns.js:r:c)
at lookupAndListen (net.js:r:c)
at Server.listen (net.js:r:c)
at Object.<anonymous> (/scripts/regression-http-close.js:r:c)
at Module._compile (module.js:r:c)
at Object.Module._extensions..js (module.js:r:c)
at Module.load (module.js:r:c)
at tryModuleLoad (module.js:r:c)
at Function.Module._load (module.js:r:c)
at Function.Module.runMain (module.js:r:c)
at startup (bootstrap_node.js:r:c)
at bootstrap_node.js:r:c
at Server.close (/scripts/regression-http-close.js:20:15)
at ____________________:0:0
at IncomingMessage.end (/scripts/regression-http-close.js:19:14)
at ____________________:0:0
at ____________________:0:0
at ClientRequest.get (/scripts/regression-http-close.js:16:9)
at ____________________:0:0
at ____________________:0:0
at Server.listen (/scripts/regression-http-close.js:15:8)
at ____________________:0:0
at ____________________:0:0
at ____________________:0:0
at Object.<anonymous> (/scripts/regression-http-close.js:11:4)
50 changes: 7 additions & 43 deletions test/expected/regression-http-parser.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,10 @@
^

Error: trace
at Socket.res.socket._read (/scripts/regression-http-parser.js:r:c)
at Socket.Readable.read (_stream_readable.js:r:c)
at addChunk (_stream_readable.js:r:c)
at readableAddChunk (_stream_readable.js:r:c)
at Socket.Readable.push (_stream_readable.js:r:c)
at TCP.onread (net.js:r:c)
at TCP.emitInitNative (internal/async_hooks.js:r:c)
at Socket.connect (net.js:r:c)
at Agent.connect [as createConnection] (net.js:r:c)
at Agent.createSocket (_http_agent.js:r:c)
at Agent.addRequest (_http_agent.js:r:c)
at new ClientRequest (_http_client.js:r:c)
at request (http.js:r:c)
at Object.get (http.js:r:c)
at Server.<anonymous> (/scripts/regression-http-parser.js:r:c)
at Object.onceWrapper (events.js:r:c)
at Server.emit (events.js:r:c)
at emitListeningNT (net.js:r:c)
at process._tickCallback (internal/process/next_tick.js:r:c)
at emitInitNative (internal/async_hooks.js:r:c)
at emitInitScript (internal/async_hooks.js:r:c)
at new TickObject (internal/process/next_tick.js:r:c)
at internalNextTick (internal/process/next_tick.js:r:c)
at Server.setupListenHandle [as _listen2] (net.js:r:c)
at TCP.emitInitNative (internal/async_hooks.js:r:c)
at createServerHandle (net.js:r:c)
at Server.setupListenHandle [as _listen2] (net.js:r:c)
at listenInCluster (net.js:r:c)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:r:c)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:r:c)
at GetAddrInfoReqWrap.emitInitNative (internal/async_hooks.js:r:c)
at Object.lookup (dns.js:r:c)
at lookupAndListen (net.js:r:c)
at Server.listen (net.js:r:c)
at Object.<anonymous> (/scripts/regression-http-parser.js:r:c)
at Module._compile (module.js:r:c)
at Object.Module._extensions..js (module.js:r:c)
at Module.load (module.js:r:c)
at tryModuleLoad (module.js:r:c)
at Function.Module._load (module.js:r:c)
at Function.Module.runMain (module.js:r:c)
at startup (bootstrap_node.js:r:c)
at bootstrap_node.js:r:c
at Socket.res.socket._read (/scripts/regression-http-parser.js:25:13)
at ____________________:0:0
at Server.<anonymous> (/scripts/regression-http-parser.js:16:8)
at ____________________:0:0
at ____________________:0:0
at ____________________:0:0
at Object.<anonymous> (/scripts/regression-http-parser.js:14:8)
33 changes: 4 additions & 29 deletions test/expected/regression-net-connect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,7 @@
^

Error: connect ECONNREFUSED 127.0.0.1:24075
at Object._errnoException (util.js:r:c)
at _exceptionWithHostPort (util.js:r:c)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:r:c)
at emitInitNative (internal/async_hooks.js:r:c)
at emitInitScript (internal/async_hooks.js:r:c)
at new TickObject (internal/process/next_tick.js:r:c)
at process.nextTick (internal/process/next_tick.js:r:c)
at _destroy (internal/streams/destroy.js:r:c)
at Socket._destroy (net.js:r:c)
at Socket.destroy (internal/streams/destroy.js:r:c)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:r:c)
at TCPConnectWrap.emitInitNative (internal/async_hooks.js:r:c)
at net.js:r:c
at defaultTriggerAsyncIdScope (internal/async_hooks.js:r:c)
at internalConnect (net.js:r:c)
at GetAddrInfoReqWrap.emitLookup [as callback] (net.js:r:c)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:r:c)
at TCP.emitInitNative (internal/async_hooks.js:r:c)
at Socket.connect (net.js:r:c)
at Object.connect (net.js:r:c)
at Object.<anonymous> (/scripts/regression-net-connect.js:r:c)
at Module._compile (module.js:r:c)
at Object.Module._extensions..js (module.js:r:c)
at Module.load (module.js:r:c)
at tryModuleLoad (module.js:r:c)
at Function.Module._load (module.js:r:c)
at Function.Module.runMain (module.js:r:c)
at startup (bootstrap_node.js:r:c)
at bootstrap_node.js:r:c
at ____________________:0:0
at ____________________:0:0
at ____________________:0:0
at Object.<anonymous> (/scripts/regression-net-connect.js:9:20)
Loading