Skip to content

Commit

Permalink
chore: introduce promiseall-no-unbounded-parallelism linter rule (#…
Browse files Browse the repository at this point in the history
…31592)

Since JavaScript is single-threaded, `Promise.all()` will only ever be used for I/O-bound tasks. However, I/O-parallelism isn't free either. Every async I/O-performing task launched will consume some FDs, and their amount is limited. If the amount of promises launched is a function of the input the program runs on, the system FDs might be exhausted. Some concurrency limit must be introduced.

This linter rule exists to remind the programmer of that fact. It triggers on every `Promise.all()` invocation and cannot be resolved; the only solution is to think about it, and then silence this rule as proof that you thought about it.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Oct 4, 2024
1 parent c1a4b97 commit a37b27e
Show file tree
Hide file tree
Showing 240 changed files with 128,669 additions and 130,160 deletions.
4 changes: 4 additions & 0 deletions packages/@aws-cdk-testing/cli-integ/lib/with-cdk-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,16 @@ export class TestFixture extends ShellHelper {

// Bootstrap stacks have buckets that need to be cleaned
const bucketNames = stacksToDelete.map(stack => outputFromStack('BucketName', stack)).filter(defined);
// Parallelism will be reasonable
// eslint-disable-next-line @aws-cdk/promiseall-no-unbounded-parallelism
await Promise.all(bucketNames.map(b => this.aws.emptyBucket(b)));
// The bootstrap bucket has a removal policy of RETAIN by default, so add it to the buckets to be cleaned up.
this.bucketsToDelete.push(...bucketNames);

// Bootstrap stacks have ECR repositories with images which should be deleted
const imageRepositoryNames = stacksToDelete.map(stack => outputFromStack('ImageRepositoryName', stack)).filter(defined);
// Parallelism will be reasonable
// eslint-disable-next-line @aws-cdk/promiseall-no-unbounded-parallelism
await Promise.all(imageRepositoryNames.map(r => this.aws.deleteImageRepository(r)));

await this.aws.deleteStacks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ test('somewhat balance', async () => {

const keys = Object.keys(counters) as Array<keyof typeof counters> ;
const pool = ResourcePool.withResources(POOL_NAME, keys);
// eslint-disable-next-line @aws-cdk/promiseall-no-unbounded-parallelism
await Promise.all(Array.from(range(N)).map(() =>
pool.using(async (x) => {
counters[x] += 1;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -986,112 +986,6 @@
"UpdatePolicy": {}
}
},
"noOptimalInstancesForARMSecurityGroup7157B016": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "batch-stack/noOptimalInstancesForARM/SecurityGroup",
"SecurityGroupEgress": [
{
"CidrIp": "0.0.0.0/0",
"Description": "Allow all outbound traffic by default",
"IpProtocol": "-1"
}
],
"VpcId": {
"Ref": "vpcA2121C38"
}
}
},
"noOptimalInstancesForARMInstanceProfileRole926AEEC5": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
]
]
}
]
}
},
"noOptimalInstancesForARMInstanceProfile37BE9D32": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Roles": [
{
"Ref": "noOptimalInstancesForARMInstanceProfileRole926AEEC5"
}
]
}
},
"noOptimalInstancesForARMF146AA4D": {
"Type": "AWS::Batch::ComputeEnvironment",
"Properties": {
"ComputeResources": {
"AllocationStrategy": "BEST_FIT_PROGRESSIVE",
"Ec2Configuration": [
{
"ImageIdOverride": {
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter"
},
"ImageType": "ECS_AL2"
}
],
"InstanceRole": {
"Fn::GetAtt": [
"noOptimalInstancesForARMInstanceProfile37BE9D32",
"Arn"
]
},
"InstanceTypes": [
"a1.large",
"m6g"
],
"MaxvCpus": 256,
"MinvCpus": 0,
"SecurityGroupIds": [
{
"Fn::GetAtt": [
"noOptimalInstancesForARMSecurityGroup7157B016",
"GroupId"
]
}
],
"Subnets": [
{
"Ref": "vpcPrivateSubnet1Subnet934893E8"
},
{
"Ref": "vpcPrivateSubnet2Subnet7031C2BA"
}
],
"Type": "EC2"
},
"ReplaceComputeEnvironment": false,
"State": "ENABLED",
"Type": "managed",
"UpdatePolicy": {}
}
},
"taggedCESecurityGroup82CCF59F": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a37b27e

Please sign in to comment.