Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not read response from a closed client #438

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: ./run-benchmarks.sh
working-directory: ./benchmark
- name: Upload Results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Benchmark Results
path: ./benchmark/jmh-result.json
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ jobs:
shell: cmd
if: matrix.os == 'windows-latest'
- name: Upload Failed Test Report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: Failed Test Report
path: target/surefire-reports
- name: Upload Coverage
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: matrix.os == 'ubuntu-latest'
with:
name: Coverage Report ${{ matrix.os }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ private Optional<Set<String>> getThingsAssociatedWithCoreDevice() {
.build();

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

Set<String> cloudThings =
cloudAssociatedDevices.flatMap(List::stream).map(AssociatedClientDevice::thingName)
cloudAssociatedDevices.stream().map(AssociatedClientDevice::thingName)
.collect(Collectors.toSet());

return Optional.of(cloudThings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import software.amazon.awssdk.services.greengrassv2.GreengrassV2ClientBuilder;
import software.amazon.awssdk.services.greengrassv2.model.AssociatedClientDevice;
import software.amazon.awssdk.services.greengrassv2.model.ListClientDevicesAssociatedWithCoreDeviceRequest;
import software.amazon.awssdk.services.greengrassv2.model.ListClientDevicesAssociatedWithCoreDeviceResponse;
import software.amazon.awssdk.services.greengrassv2.paginators.ListClientDevicesAssociatedWithCoreDeviceIterable;
import software.amazon.awssdk.services.greengrassv2data.GreengrassV2DataClient;
import software.amazon.awssdk.services.greengrassv2data.model.ResourceNotFoundException;
Expand All @@ -37,7 +36,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.stream.Collectors;
import javax.inject.Inject;

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


Stream<List<AssociatedClientDevice>> getThingsAssociatedWithCoreDevice();
List<AssociatedClientDevice> getThingsAssociatedWithCoreDevice();

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

@Override
public Stream<List<AssociatedClientDevice>> getThingsAssociatedWithCoreDevice() {
public List<AssociatedClientDevice> getThingsAssociatedWithCoreDevice() {
String thingName = Coerce.toString(deviceConfiguration.getThingName());

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

return responses.stream()
.map(ListClientDevicesAssociatedWithCoreDeviceResponse::associatedClientDevices);
return responses.stream().flatMap(response -> response.associatedClientDevices().stream())
.collect(Collectors.toList());
}
}

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

if (Utils.isEmpty(awsRegion)) {
return clientBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -22,7 +23,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.stream.Collectors;

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

@Override
public Stream<List<AssociatedClientDevice>> getThingsAssociatedWithCoreDevice() {
public List<AssociatedClientDevice> getThingsAssociatedWithCoreDevice() {
ThingsAttachedToCorePaginator paginator = new ThingsAttachedToCorePaginator(
new ListClientDevicesAssociatedWithCoreDeviceResponseFetcher(this.thingsAttachedToCore));

return paginator.stream();
return paginator.stream().flatMap(Collection::stream).collect(Collectors.toList());
}

/**
Expand Down
Loading