@@ -11,6 +11,7 @@ import { performance } from 'perf_hooks';
11
11
import * as url from 'url' ;
12
12
import { LoaderStats } from 'vs/base/common/amd' ;
13
13
import { VSBuffer } from 'vs/base/common/buffer' ;
14
+ import { setUnexpectedErrorHandler } from 'vs/base/common/errors' ;
14
15
import { isEqualOrParent } from 'vs/base/common/extpath' ;
15
16
import { Disposable , DisposableStore } from 'vs/base/common/lifecycle' ;
16
17
import { connectionTokenQueryName , FileAccess , Schemas } from 'vs/base/common/network' ;
@@ -647,6 +648,22 @@ export async function createServer(address: string | net.AddressInfo | null, arg
647
648
const disposables = new DisposableStore ( ) ;
648
649
const { socketServer, instantiationService } = await setupServerServices ( connectionToken , args , REMOTE_DATA_FOLDER , disposables ) ;
649
650
651
+ // Set the unexpected error handler after the services have been initialized, to avoid having
652
+ // the telemetry service overwrite our handler
653
+ instantiationService . invokeFunction ( ( accessor ) => {
654
+ const logService = accessor . get ( ILogService ) ;
655
+ setUnexpectedErrorHandler ( err => {
656
+ // See https://github.com/microsoft/vscode-remote-release/issues/6481
657
+ // In some circumstances, console.error will throw an asynchronous error. This asynchronous error
658
+ // will end up here, and then it will be logged again, thus creating an endless asynchronous loop.
659
+ // Here we try to break the loop by ignoring EPIPE errors that include our own unexpected error handler in the stack.
660
+ if ( err && err . code === 'EPIPE' && err . syscall === 'write' && err . stack && / u n e x p e c t e d E r r o r H a n d l e r / . test ( err . stack ) ) {
661
+ return ;
662
+ }
663
+ logService . error ( err ) ;
664
+ } ) ;
665
+ } ) ;
666
+
650
667
//
651
668
// On Windows, exit early with warning message to users about potential security issue
652
669
// if there is node_modules folder under home drive or Users folder.
0 commit comments