0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
Commit Graph

38 Commits

Author SHA1 Message Date
Julien Gilli
90204cc468 domains: clear stack when no error handler
Clear domains stack __even if no domain error handler is set__ so that
code running in the process' uncaughtException handler, or any code that
may be executed when an error is thrown and not caught and that is not
the domain's error handler, doesn't run in the context of the domain
within which the error was thrown.

PR: #4659
PR-URL: https://github.com/nodejs/node/pull/4659
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-01-13 10:55:15 -08:00
Julien Gilli
425a3545d2 domains: fix handling of uncaught exceptions
Fix node exiting due to an exception being thrown rather than emitting
an `'uncaughtException'` event on the process object when:
1. no error handler is set on the domain within which an error is thrown
2. an `'uncaughtException'` event listener is set on the process

Also fix an issue where the process would not abort in the proper
function call if an error is thrown within a domain with no error
handler and `--abort-on-uncaught-exception` is used.

Finally, change the behavior of --abort-on-uncaught-exception so that,
if the domain within which the error is thrown has no error handler, but
a domain further up the domains stack has one, the process will not
abort.

Fixes #3607 and #3653.

PR: #3654
PR-URL: https://github.com/nodejs/node/pull/3654
Reviewed-By: Chris Dickinson <chris@neversaw.us>
2015-12-11 14:33:48 -08:00
Jeremy Whitlock
77a10ed05f src: fix --abort-on-uncaught-exception
Revert 0af4c9ea74, parts of
921f2de6cf and port
https://github.com/nodejs/node-v0.x-archive/pull/25835 from v0.12 to
master so that node aborts at the right time when an error is thrown
and --abort-on-uncaught-exception is used.

Fixes #3035.

PR: #3036
PR-URL: https://github.com/nodejs/node/pull/3036
Reviewed-By: Ben Noordhuis <ben@strongloop.com>
2015-10-05 18:12:43 -07:00
Ben Noordhuis
70d1f32f56 deps: update v8 to 4.4.63.9
Upgrade the bundled V8 and update code in src/ and lib/ to the new API.

Notable backwards incompatible changes are the removal of the smalloc
module and dropped support for CESU-8 decoding.  CESU-8 support can be
brought back if necessary by doing UTF-8 decoding ourselves.

This commit includes https://codereview.chromium.org/1192973004 to fix
a build error on python 2.6 systems.  The original commit log follows:

    Use optparse in js2c.py for python compatibility

    Without this change, V8 won't build on RHEL/CentOS 6 because the
    distro python is too old to know about the argparse module.

PR-URL: https://github.com/nodejs/io.js/pull/2022
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-08-04 11:56:14 -07:00
cjihrig
804e7aa9ab lib: use const to define constants
This commit replaces a number of var statements throughout
the lib code with const statements.

PR-URL: https://github.com/iojs/io.js/pull/541
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21 16:21:31 -05:00
isaacs
3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00
Chris Dickinson
6a29356451 domain: add soft deprecation notice
Per the TC meeting on 2014-12-10, domains will be "soft deprecated"
until a suitable replacement API is available; at which time they
will be fully deprecated. Full deprecation will include references
to replacement API and the application of util.deprecate to the domain
api.

PR-URL: https://github.com/iojs/io.js/pull/141
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-12 09:52:05 -08:00
micnic
8c69d7bed4 domain: forward args to .run(fn)
Adds the feature to define arguments for the function called in
domain.run(), this is supposed to be useful when a function is called from
another context and some values from the current context are needed as
arguments, it's similar to the callback from setTimeout or setInterval.

PR-URL: https://github.com/iojs/io.js/pull/15
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-12 12:14:11 +11:00
Ben Noordhuis
21130c7d6f lib: turn on strict mode
Turn on strict mode for the files in the lib/ directory.  It helps
catch bugs and can have a positive effect on performance.

PR-URL: https://github.com/node-forward/node/pull/64
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-11-22 17:23:30 +01:00
Brian White
03e9f84933 lib: remove unused variables
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-11 20:41:12 -07:00
Alex Kocharin
42a33c1bb8 domain: don't crash on "throw null"
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-04-02 15:36:30 -07:00
Trevor Norris
24856f04b2 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	lib/domain.js
2014-01-15 13:49:55 -08:00
Ryan Graham
7f81ca2c47 domains: exit() only affects active domains
domain.create().exit() should not clear the domain stack if the domain
instance does not exist within the stack.

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-01-15 12:27:10 -08:00
Ryan Graham
5106cadffb domain: fix off-by-one in Domain.exit()
We want to clear the found domain and the domains after it.

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-01-09 15:25:58 -08:00
Trevor Norris
828f14556e src: revert domain using AsyncListeners
This is a slightly modified revert of bc39bdd.

Getting domains to use AsyncListeners became too much of a challenge
with many edge cases. While this is still a goal, it will have to be
deferred for now until more test coverage can be provided.
2014-01-09 13:25:20 -08:00
Trevor Norris
d9fc6af32a node: change AsyncListener API
There was a flaw in the old API that has been fixed. Now the
asyncListener callback is now the "create" object property in the
callback object, and is optional.
2014-01-03 13:20:23 -08:00
Trevor Norris
bc39bdd995 domain: use AsyncListener API
The domain module has been switched over to use the domain module API as
much as currently possible. There are still some hooks in the
EventEmitter, but hopefully we can remove those in the future.
2013-10-31 16:34:35 -07:00
Forrest L Norvell
d86814aeca domains: deprecate domain.dispose().
Follows @isaacs's recommendations in joyent/node#5018. Includes some
updates to documentation but not examples.

Conflicts:
	lib/domain.js
2013-08-27 11:05:14 -07:00
Trevor Norris
467e00ed02 domain: move error handling directly into instance
Instead of doing all the domain handling in core, allow the domain to
set an error handler that'll take care of it all. This way the domain
error handling can be abstracted enough for any user to use it.
2013-08-23 10:14:10 -07:00
Matthew Aynalem
c171c490f2 fixes #6031 spelling errors
explictly => explicitly
accesss => access
througput => throughput
epxression => expression
communiction => communication
becuase => because
repersent => represent
condonitions => conditions
decompresion => decompression
intentially => intentionally
eventes => events
listning => listening
resicved => received
becuase => because
fundimental => fundamental
colapse => collapse
privlages => privileges
sufficently => sufficiently
hapepns => happens
expliclitly => explicitly
thier => their
shold => should
2013-08-19 16:42:16 -07:00
Trevor Norris
3f5d5847e2 domain: share object and state with native land
Change process.domain to use a getter/setter and access that property
via an array index. These are much faster to get from c++, and it can be
passed to _setupDomainUse and stored as a Persistent<Array>.

InDomain() and GetDomain() as trivial ways to access the domain
information in the native layer. Important because we'll be able to
quickly access if a domain is active. Instead of just whether the domain
module has been loaded.
2013-08-09 16:54:45 -07:00
isaacs
22c68fdc1d src: Replace macros with util functions 2013-08-01 15:08:01 -07:00
Ben Noordhuis
0330bdf519 lib: macro-ify type checks
Increases the grep factor. Makes it easier to harmonize type checks
across the code base.
2013-07-24 21:49:35 +02:00
Trevor Norris
33fae69779 domain: change name for domain setup
The name UsingDomains is misleading for a function that initializes
domains for use.
2013-04-10 23:51:16 +02:00
Trevor Norris
f0b68892d4 domain: fix domain callback from MakeCallback
Since _tickCallback and _tickDomainCallback were both called from
MakeCallback, it was possible for a callback to be called that required
a domain directly to _tickCallback.

The fix was to implement process.usingDomains(). This will set all
applicable functions to their domain counterparts, and set a flag in cc
to let MakeCallback know domain callbacks always need to be checked.

Added test in own file. It's important that the test remains isolated.
2013-03-26 21:26:17 -07:00
Trevor Norris
0c1e7b53d0 process: separate nextTick domain logic
It's cleaner to only load domain ticker logic when the domains are being
used. This makes execution slightly quicker in both cases, and simpler
from the spinner since there is no need to check if the latest callback
requires use of domains.
2013-02-27 16:37:10 -08:00
isaacs
ec8ebaf300 domain: use camelCase instead of snake_case
While it's true that error objects have a history of getting snake_case
properties attached by the host system, it's a point of confusion to
Node users that comes up a lot.  It's still 'experimental', so best to
change this sooner rather than later.
2012-12-29 10:37:31 -08:00
isaacs
4401bb47bf domain: Do not use uncaughtException handler
This adds a process._fatalException method which is called into from
C++ in order to either emit the 'uncaughtException' method, or emit
'error' on the active domain.

The 'uncaughtException' event is an implementation detail that it would
be nice to deprecate one day, so exposing it as part of the domain
machinery is not ideal.

Fix #4375
2012-12-29 10:37:30 -08:00
Ryunosuke SATO
697484df82 domain: speed up domain.create
Use `EventEmitter.call` instead of `EventEmitter.apply` because of performance.
2012-12-27 17:45:36 -08:00
isaacs
2a9a5e2318 domain: Remove stray console.log 2012-09-25 11:08:52 -07:00
isaacs
0400571676 domain: Properly exit() on domain disposal
This addresses #4034.  There are two problems happening:

1. The domain is not exited automatically when calling dispose() on it.
Then, since the domain is disposed, attempting to exit it again will do
nothing.

2. The active domain is stored on process.domain.  Since thrown errors
call `process.emit('uncaughtException', er)`, and the process is an
event emitter with a `.domain` member, it re-enters the domain a second
time before calling the error handler, pushing it onto the stack again.

Thus, if the handler calls `domain.dispose()`, then the domain is now on
the stack twice, and cannot be exited properly.  Since the domain is
disposed, any subsequent IO will be no-op'ed, since we've declared that
this context is done and best forgotten.

The solution here is twofold:

1. In EventEmitter.emit, do not enter the domain if `this===process`.
2. Automatically exit the domain when calling `domain.dispose()`.
2012-09-21 09:22:50 -07:00
isaacs
d6b78d0e37 domain: Fix stack leak on error 2012-07-16 18:04:55 -07:00
Toshihiro Nakamura
6530310ed5 domain: Remove first arg from intercepted fn
Fix to remove the first-arg, in case arguments length is more than 2
Add domain.intercept() test about first-arg removal
2012-07-09 09:37:46 -07:00
Andreas Madsen
535e109a3a domain: run now return callback result
both domain.bind and domain.intercept act this way
2012-06-09 18:15:38 +02:00
Andreas Madsen
77cfbd9f2d domain: dry decorate using util._extend 2012-06-09 18:15:38 +02:00
Marc Harter
569acea0ee Fix #3379 prevent domain.intercept passing 1st arg to cb 2012-06-08 23:32:13 -07:00
isaacs
d8b33dc147 lint 2012-04-17 15:52:57 -07:00
isaacs
963459d736 Domain feature
This is a squashed commit of the main work done on the domains-wip branch.

The original commit messages are preserved for posterity:

* Implicitly add EventEmitters to active domain
* Implicitly add timers to active domain
* domain: add members, remove ctor cb
* Don't hijack bound callbacks for Domain error events
* Add dispose method
* Add domain.remove(ee) method
* A test of multiple domains in process at once
* Put the active domain on the process object
* Only intercept error arg if explicitly requested
* Typo
* Don't auto-add new domains to the current domain

    While an automatic parent/child relationship is sort of neat,
    and leads to some nice error-bubbling characteristics, it also
    results in keeping a reference to every EE and timer created,
    unless domains are explicitly disposed of.

* Explicitly adding one domain to another is still fine, of course.
* Don't allow circular domain->domain memberships
* Disposing of a domain removes it from its parent
* Domain disposal turns functions into no-ops
* More documentation of domains
* More thorough dispose() semantics
* An example using domains in an HTTP server
* Don't handle errors on a disposed domain
* Need to push, even if the same domain is entered multiple times
* Array.push is too slow for the EE Ctor
* lint domain
* domain: docs
* Also call abort and destroySoon to clean up event emitters
* domain: Wrap destroy methods in a try/catch
* Attach tick callbacks to active domain
* domain: Only implicitly bind timers, not explicitly
* domain: Don't fire timers when disposed.
* domain: Simplify naming so that MakeCallback works on Timers
* Add setInterval and nextTick to domain test
* domain: Make stack private
2012-04-17 13:14:55 -07:00