@@ -54,6 +54,22 @@ export class JvmInterceptor implements Interceptor {
5454 // since it's a bit expensive.
5555 if ( type === 'summary' ) return { } ;
5656
57+ if ( ! this . targetsPromise ) {
58+ // We cache the targets lookup whilst it's active, so that concurrent calls
59+ // all just run one lookup and return the same result.
60+ this . targetsPromise = this . getTargets ( )
61+ . finally ( ( ) => { this . targetsPromise = undefined ; } ) ;
62+ }
63+ const targets = await this . targetsPromise
64+
65+ return {
66+ jvmTargets : _ . keyBy ( targets , 'pid' )
67+ } ;
68+ }
69+
70+ private targetsPromise : Promise < JvmTarget [ ] > | undefined ;
71+
72+ private async getTargets ( ) : Promise < JvmTarget [ ] > {
5773 const listTargetsOutput = await spawnToResult (
5874 'java' , [
5975 '-jar' , OVERRIDE_JAVA_AGENT ,
@@ -63,10 +79,10 @@ export class JvmInterceptor implements Interceptor {
6379
6480 if ( listTargetsOutput . exitCode !== 0 ) {
6581 reportError ( `JVM target lookup failed with status ${ listTargetsOutput . exitCode } ` ) ;
66- return { jvmTargets : { } } ;
82+ return [ ] ;
6783 }
6884
69- const targets = listTargetsOutput . stdout
85+ return listTargetsOutput . stdout
7086 . split ( '\n' )
7187 . filter ( line => line . includes ( ':' ) )
7288 . map ( ( line ) => {
@@ -84,10 +100,6 @@ export class JvmInterceptor implements Interceptor {
84100 // Exclude our own attacher and/or list-target queries from this list
85101 ! target . name . includes ( OVERRIDE_JAVA_AGENT )
86102 ) ;
87-
88- return {
89- jvmTargets : _ . keyBy ( targets , 'pid' )
90- } ;
91103 }
92104
93105 async activate ( proxyPort : number , options : {
0 commit comments