File tree Expand file tree Collapse file tree
azure-resources/src/main/java/io/opentelemetry/contrib/azure/resource
jfr-connection/src/main/java/io/opentelemetry/contrib/jfr/connection Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,9 +46,7 @@ static Optional<String> fetchMetadata(URL url) {
4646 .connectTimeout (TIMEOUT )
4747 .readTimeout (TIMEOUT )
4848 .build ();
49-
5049 Request request = new Request .Builder ().url (url ).get ().addHeader ("Metadata" , "true" ).build ();
51-
5250 try (Response response = client .newCall (request ).execute ()) {
5351 int responseCode = response .code ();
5452 if (responseCode != 200 ) {
@@ -62,11 +60,13 @@ static Optional<String> fetchMetadata(URL url) {
6260 + response .message ());
6361 return Optional .empty ();
6462 }
65-
6663 return Optional .of (requireNonNull (response .body ()).string ());
6764 } catch (IOException e ) {
6865 logger .log (Level .FINE , "Failed to fetch Azure VM metadata" , e );
6966 return Optional .empty ();
67+ } finally {
68+ client .dispatcher ().executorService ().shutdown ();
69+ client .connectionPool ().evictAll ();
7070 }
7171 }
7272
Original file line number Diff line number Diff line change @@ -33,13 +33,15 @@ public JfcFileConfiguration(InputStream configurationFile) {
3333 }
3434
3535 private static String readConfigurationFile (InputStream inputStream ) {
36- if (inputStream != null ) {
37- return new BufferedReader (new InputStreamReader (inputStream , StandardCharsets .UTF_8 ))
38- .lines ()
39- .collect (Collectors .joining ());
40- } else {
36+ if (inputStream == null ) {
4137 throw new IllegalArgumentException ("Null configuration provided" );
4238 }
39+ try (BufferedReader reader =
40+ new BufferedReader (new InputStreamReader (inputStream , StandardCharsets .UTF_8 ))) {
41+ return reader .lines ().collect (Collectors .joining ());
42+ } catch (IOException e ) {
43+ throw new IllegalStateException ("Failed to read JFC configuration file" , e );
44+ }
4345 }
4446
4547 @ Override
You can’t perform that action at this time.
0 commit comments