Skip to content

Commit 1dbaf82

Browse files
authored
fix: do not read response from a closed client (#438)
1 parent 27ef646 commit 1dbaf82

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
run: ./run-benchmarks.sh
2222
working-directory: ./benchmark
2323
- name: Upload Results
24-
uses: actions/upload-artifact@v3
24+
uses: actions/upload-artifact@v4
2525
with:
2626
name: Benchmark Results
2727
path: ./benchmark/jmh-result.json

.github/workflows/maven.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ jobs:
3737
shell: cmd
3838
if: matrix.os == 'windows-latest'
3939
- name: Upload Failed Test Report
40-
uses: actions/upload-artifact@v3
40+
uses: actions/upload-artifact@v4
4141
if: failure()
4242
with:
4343
name: Failed Test Report
4444
path: target/surefire-reports
4545
- name: Upload Coverage
46-
uses: actions/upload-artifact@v3
46+
uses: actions/upload-artifact@v4
4747
if: matrix.os == 'ubuntu-latest'
4848
with:
4949
name: Coverage Report ${{ matrix.os }}

src/main/java/com/aws/greengrass/clientdevices/auth/certificate/infra/BackgroundCertificateRefresh.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ private Optional<Set<String>> getThingsAssociatedWithCoreDevice() {
202202
.build();
203203

204204
try {
205-
Stream<List<AssociatedClientDevice>> cloudAssociatedDevices =
205+
List<AssociatedClientDevice> cloudAssociatedDevices =
206206
RetryUtils.runWithRetry(retryConfig, iotAuthClient::getThingsAssociatedWithCoreDevice,
207207
"get-things-associated-with-core-device", logger);
208208

209209
Set<String> cloudThings =
210-
cloudAssociatedDevices.flatMap(List::stream).map(AssociatedClientDevice::thingName)
210+
cloudAssociatedDevices.stream().map(AssociatedClientDevice::thingName)
211211
.collect(Collectors.toSet());
212212

213213
return Optional.of(cloudThings);

src/main/java/com/aws/greengrass/clientdevices/auth/iot/IotAuthClient.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import software.amazon.awssdk.services.greengrassv2.GreengrassV2ClientBuilder;
2525
import software.amazon.awssdk.services.greengrassv2.model.AssociatedClientDevice;
2626
import software.amazon.awssdk.services.greengrassv2.model.ListClientDevicesAssociatedWithCoreDeviceRequest;
27-
import software.amazon.awssdk.services.greengrassv2.model.ListClientDevicesAssociatedWithCoreDeviceResponse;
2827
import software.amazon.awssdk.services.greengrassv2.paginators.ListClientDevicesAssociatedWithCoreDeviceIterable;
2928
import software.amazon.awssdk.services.greengrassv2data.GreengrassV2DataClient;
3029
import software.amazon.awssdk.services.greengrassv2data.model.ResourceNotFoundException;
@@ -37,7 +36,7 @@
3736
import java.util.List;
3837
import java.util.Objects;
3938
import java.util.Optional;
40-
import java.util.stream.Stream;
39+
import java.util.stream.Collectors;
4140
import javax.inject.Inject;
4241

4342
public interface IotAuthClient {
@@ -50,7 +49,7 @@ public interface IotAuthClient {
5049
boolean isThingAttachedToCertificate(Thing thing, String certificateId) throws CloudServiceInteractionException;
5150

5251

53-
Stream<List<AssociatedClientDevice>> getThingsAssociatedWithCoreDevice();
52+
List<AssociatedClientDevice> getThingsAssociatedWithCoreDevice();
5453

5554
class Default implements IotAuthClient {
5655
private static final Logger logger = LogManager.getLogger(Default.class);
@@ -184,7 +183,7 @@ public boolean isThingAttachedToCertificate(Thing thing, String certificateId)
184183
}
185184

186185
@Override
187-
public Stream<List<AssociatedClientDevice>> getThingsAssociatedWithCoreDevice() {
186+
public List<AssociatedClientDevice> getThingsAssociatedWithCoreDevice() {
188187
String thingName = Coerce.toString(deviceConfiguration.getThingName());
189188

190189
ListClientDevicesAssociatedWithCoreDeviceRequest request =
@@ -194,20 +193,19 @@ public Stream<List<AssociatedClientDevice>> getThingsAssociatedWithCoreDevice()
194193
ListClientDevicesAssociatedWithCoreDeviceIterable responses =
195194
client.listClientDevicesAssociatedWithCoreDevicePaginator(request);
196195

197-
return responses.stream()
198-
.map(ListClientDevicesAssociatedWithCoreDeviceResponse::associatedClientDevices);
196+
return responses.stream().flatMap(response -> response.associatedClientDevices().stream())
197+
.collect(Collectors.toList());
199198
}
200199
}
201200

202201
// TODO: This should not live here ideally it should be returned by the clientFactory but we
203202
// are adding it here to avoid introducing new changes to the nucleus
204203
private GreengrassV2Client getGGV2Client() {
205204
String awsRegion = Coerce.toString(deviceConfiguration.getAWSRegion());
206-
GreengrassV2ClientBuilder clientBuilder =
207-
GreengrassV2Client.builder().httpClientBuilder(ProxyUtils.getSdkHttpClientBuilder()
208-
.useIdleConnectionReaper(false))
209-
.credentialsProvider(lazyCredentialProvider).overrideConfiguration(
210-
ClientOverrideConfiguration.builder().retryPolicy(RetryMode.STANDARD).build());
205+
GreengrassV2ClientBuilder clientBuilder = GreengrassV2Client.builder()
206+
.httpClientBuilder(ProxyUtils.getSdkHttpClientBuilder().useIdleConnectionReaper(false))
207+
.credentialsProvider(lazyCredentialProvider).overrideConfiguration(
208+
ClientOverrideConfiguration.builder().retryPolicy(RetryMode.STANDARD).build());
211209

212210
if (Utils.isEmpty(awsRegion)) {
213211
return clientBuilder.build();

src/test/java/com/aws/greengrass/clientdevices/auth/iot/IotAuthClientFake.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.time.Instant;
1414
import java.util.ArrayList;
15+
import java.util.Collection;
1516
import java.util.Collections;
1617
import java.util.HashMap;
1718
import java.util.HashSet;
@@ -22,7 +23,7 @@
2223
import java.util.Optional;
2324
import java.util.Set;
2425
import java.util.function.Supplier;
25-
import java.util.stream.Stream;
26+
import java.util.stream.Collectors;
2627

2728
/**
2829
* IoT Auth Client Fake allows test writers to set up valid and invalid certificates, as well as Thing <-> certificate
@@ -126,11 +127,11 @@ public void detachThingFromCore(Supplier<String> thingName) {
126127
}
127128

128129
@Override
129-
public Stream<List<AssociatedClientDevice>> getThingsAssociatedWithCoreDevice() {
130+
public List<AssociatedClientDevice> getThingsAssociatedWithCoreDevice() {
130131
ThingsAttachedToCorePaginator paginator = new ThingsAttachedToCorePaginator(
131132
new ListClientDevicesAssociatedWithCoreDeviceResponseFetcher(this.thingsAttachedToCore));
132133

133-
return paginator.stream();
134+
return paginator.stream().flatMap(Collection::stream).collect(Collectors.toList());
134135
}
135136

136137
/**

0 commit comments

Comments
 (0)