Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix(node): fix #1164, don't patch uncaughtException to prevent endless loop. #1170

Merged
merged 1 commit into from
Dec 12, 2018
Merged
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: false
dist: trusty
cache: yarn
node_js:
- 8
- 10
env:
global:
- BROWSER_PROVIDER_READY_FILE=/tmp/sauce-connect-ready
Expand Down
8 changes: 6 additions & 2 deletions lib/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @suppress {missingRequire}
*/

import {ADD_EVENT_LISTENER_STR, attachOriginToPatched, FALSE_STR, ObjectGetPrototypeOf, REMOVE_EVENT_LISTENER_STR, TRUE_STR, ZONE_SYMBOL_PREFIX, zoneSymbol} from './utils';
import {ADD_EVENT_LISTENER_STR, attachOriginToPatched, FALSE_STR, isNode, ObjectGetPrototypeOf, REMOVE_EVENT_LISTENER_STR, TRUE_STR, ZONE_SYMBOL_PREFIX, zoneSymbol} from './utils';

/** @internal **/
interface EventTaskData extends TaskData {
Expand Down Expand Up @@ -330,10 +330,15 @@ export function patchEventTarget(
returnTarget = false, prepend = false) {
return function() {
const target = this || _global;
const eventName = arguments[0];
let delegate = arguments[1];
if (!delegate) {
return nativeListener.apply(this, arguments);
}
if (isNode && eventName === 'uncaughtException') {
// don't patch uncaughtException of nodejs to prevent endless loop
return nativeListener.apply(this, arguments);
}

// don't create the bind delegate function for handleEvent
// case here to improve addEventListener performance
Expand All @@ -350,7 +355,6 @@ export function patchEventTarget(
return;
}

const eventName = arguments[0];
const options = arguments[2];

if (blackListedEvents) {
Expand Down
8 changes: 7 additions & 1 deletion test/node/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,10 @@ describe('nodejs EventEmitter', () => {
expect(emitter.listeners('removeListener').length).toBe(0);
});
});
});
it('should not enter endless loop when register uncaughtException to process', () => {
require('domain');
zoneA.run(() => {
process.on('uncaughtException', function() {});
});
});
});
Loading