0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
nodejs/lib
Trevor Norris 062beb08df
async_hooks: don't abort unnecessarily
* id values of -1 are allowed. They indicate that the id was never
  correctly assigned to the async resource. These will appear in any
  call graph, and will only be apparent to those using the async_hooks
  module, then reported in an issue.
* ids < -1 are still not allowed and will cause the application to
  exit the process; because there is no scenario where this should ever
  happen.
* Add asyncId range checks to emitAfterScript().
* Fix emitBeforeScript() range checks which should have been || not &&.
* Replace errors with entries in internal/errors.
* Fix async_hooks tests that check for exceptions to match new
  internal/errors entries.

NOTE: emit{Before,After,Destroy}() must continue to exit the process
because in the case of an exception during hook execution the state of
the application is unknowable. For example, an exception could cause a
memory leak:

    const id_map = new Map();

    before(id) {
      id_map.set(id, /* data object or similar */);
    },
    after(id) {
      throw new Error('id never dies!');
      id_map.delete(id);
    }

Allowing a recoverable exception may also cause an abort because of a
stack check in Environment::AsyncHooks::pop_ids() that verifies the
async id and pop'd ids match. This case would be more difficult to debug
than if fatalError() (lib/async_hooks.js) was called immediately.

    try {
      async_hooks.emitBefore(null, NaN);
    } catch (e) { }
    // do something
    async_hooks.emitAfter(5);

It also allows an edge case where emitBefore() could be called twice and
not have the pop_ids() CHECK fail:

    try {
      async_hooks.emitBefore(5, NaN);
    } catch (e) { }
    async_hooks.emitBefore(5);
    // do something
    async_hooks.emitAfter(5);

There is the option of allowing mismatches in the stack and ignoring the
check if no async hooks are enabled, but I don't believe going this far
is necessary.

PR-URL: https://github.com/nodejs/node/pull/14722
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-08-14 23:21:01 +02:00
..
internal async_hooks: don't abort unnecessarily 2017-08-14 23:21:01 +02:00
_http_agent.js http: check for handle before running asyncReset() 2017-07-24 20:42:24 -04:00
_http_client.js errors: migrate _http_outgoing 2017-08-14 17:19:19 -04:00
_http_common.js
_http_incoming.js http: suppress data event if req aborted 2017-05-31 10:39:17 +02:00
_http_outgoing.js errors: migrate _http_outgoing 2017-08-14 17:19:19 -04:00
_http_server.js errors: migrate _http_outgoing 2017-08-14 17:19:19 -04:00
_stream_duplex.js
_stream_passthrough.js
_stream_readable.js stream: support readable/writableHWM for Duplex 2017-08-08 11:18:25 +02:00
_stream_transform.js stream: use more explicit statements 2017-06-29 18:03:54 +02:00
_stream_wrap.js stream: use more explicit statements 2017-06-29 18:03:54 +02:00
_stream_writable.js stream: support readable/writableHWM for Duplex 2017-08-08 11:18:25 +02:00
_tls_common.js tls: fix empty issuer/subject/infoAccess parsing 2017-07-27 17:36:50 +02:00
_tls_legacy.js doc, lib, test: do not re-require needlessly 2017-07-21 20:40:52 +03:00
_tls_wrap.js tls: add tlsSocket.disableRenegotiation() 2017-08-04 12:55:30 -07:00
.eslintrc.yaml tools: remove legacy indentation linting 2017-07-30 09:21:52 -07:00
assert.js assert: optimize code path for deepEqual Maps 2017-08-13 13:58:11 -04:00
async_hooks.js async_hooks: don't abort unnecessarily 2017-08-14 23:21:01 +02:00
buffer.js buffer: refactor module.exports, imports 2017-07-24 07:24:53 -07:00
child_process.js lib: modify destructuring for indentation 2017-07-25 12:21:26 -07:00
cluster.js lib: use consistent indentation for ternaries 2017-07-07 06:57:16 -07:00
console.js console: coerce label to string in console.time() 2017-08-07 22:22:59 -07:00
constants.js
crypto.js lib: remove excess indentation 2017-07-07 13:18:19 -07:00
dgram.js dgram: add custom lookup function in sockets 2017-08-02 20:32:51 -04:00
dns.js dns: name generated functions 2017-08-01 19:57:24 +02:00
domain.js
events.js lib: update indentation of ternaries 2017-07-17 22:09:46 -07:00
fs.js fs: invoke callbacks with undefined context 2017-08-10 09:11:38 -07:00
http2.js http2: introducing HTTP/2 2017-08-04 12:55:44 -07:00
http.js
https.js https: make opts optional & immutable when create 2017-06-14 15:14:34 -04:00
inspector.js lib,src: fix consistent spacing inside braces 2017-07-21 15:13:47 -04:00
module.js lib: include cached modules in module.children 2017-07-24 16:56:31 +02:00
net.js net: use rest parameters instead of arguments 2017-08-10 14:09:18 +02:00
os.js os: add CIDR support 2017-08-14 15:43:10 -04:00
path.js path: fix win32 volume-relative paths 2017-07-30 19:24:23 +08:00
process.js
punycode.js
querystring.js querystring: avoid indexOf when parsing 2017-08-09 14:03:48 -04:00
readline.js lib: use Timer.now() in readline module 2017-08-09 22:59:25 -07:00
repl.js repl: include folder extensions in autocomplete 2017-08-13 01:03:30 -07:00
stream.js stream: support Uint8Array input to methods 2017-05-27 11:19:39 +02:00
string_decoder.js
sys.js
timers.js lib: remove excess indentation 2017-07-07 13:18:19 -07:00
tls.js tls: migrate tls.js to use internal/errors.js 2017-07-18 14:03:23 -04:00
tty.js lib: fix typos 2017-06-19 18:18:56 +02:00
url.js lib: update indentation of ternaries 2017-07-17 22:09:46 -07:00
util.js util: improve util.inspect performance 2017-08-13 13:52:33 -04:00
v8.js v8: add new to the throw statement 2017-06-28 20:00:42 +02:00
vm.js
zlib.js zlib: fix interaction of flushing and needDrain 2017-07-31 22:44:05 +02:00