@@ -54,6 +54,22 @@ export class JvmInterceptor implements Interceptor {
54
54
// since it's a bit expensive.
55
55
if ( type === 'summary' ) return { } ;
56
56
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 [ ] > {
57
73
const listTargetsOutput = await spawnToResult (
58
74
'java' , [
59
75
'-jar' , OVERRIDE_JAVA_AGENT ,
@@ -63,10 +79,10 @@ export class JvmInterceptor implements Interceptor {
63
79
64
80
if ( listTargetsOutput . exitCode !== 0 ) {
65
81
reportError ( `JVM target lookup failed with status ${ listTargetsOutput . exitCode } ` ) ;
66
- return { jvmTargets : { } } ;
82
+ return [ ] ;
67
83
}
68
84
69
- const targets = listTargetsOutput . stdout
85
+ return listTargetsOutput . stdout
70
86
. split ( '\n' )
71
87
. filter ( line => line . includes ( ':' ) )
72
88
. map ( ( line ) => {
@@ -84,10 +100,6 @@ export class JvmInterceptor implements Interceptor {
84
100
// Exclude our own attacher and/or list-target queries from this list
85
101
! target . name . includes ( OVERRIDE_JAVA_AGENT )
86
102
) ;
87
-
88
- return {
89
- jvmTargets : _ . keyBy ( targets , 'pid' )
90
- } ;
91
103
}
92
104
93
105
async activate ( proxyPort : number , options : {
0 commit comments