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

(ecs): I get an error in BaseService.RegisterLoadBalancerTargets #17876

Closed
aetos382 opened this issue Dec 7, 2021 · 4 comments
Closed

(ecs): I get an error in BaseService.RegisterLoadBalancerTargets #17876

aetos382 opened this issue Dec 7, 2021 · 4 comments
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. jsii This issue originates in jsii, or this feature must be implemented in jsii. p2

Comments

@aetos382
Copy link

aetos382 commented Dec 7, 2021

What is the problem?

I am using FargateService.RegisterLoadBalancerTargets in CDK for C#.
This method was successfully synthesized in CDK v1.132, but fails in v1.133 and later (including v2.0).

Reproduction Steps

  1. git clone https://github.com/aetos382/cdk-synth-error
  2. cd cdk-synth-error
  3. cd CdkV132
  4. npm install
  5. npx cdk synth # It is synthesized successfully.
  6. cd ../CdkV133 # Also reproduced in CdkV134 and CdkV2
  7. npm install
  8. npx cdk synth # An error occurs.

What did you expect to happen?

I can synthesize the stack successfully.

What actually happened?

I get an error with CDK v1.133 or later.

Missing required properties for @aws-cdk/aws-elasticloadbalancingv2.AddApplicationTargetGroupsProps: targetGroups

CDK CLI Version

1.133.0 (build 2dea31a)

Framework Version

.NET 6

Node.js Version

v16.13.0

OS

Windows 10

Language

.NET

Language Version

C# 10

Other information

Unhandled exception. Amazon.JSII.Runtime.JsiiException: Amazon.JSII.Runtime.JsiiException: Amazon.JSII.Runtime.JsiiException: Missing required properties for @aws-cdk/aws-elasticloadbalancingv2.AddApplicationTargetGroupsProps: targetGroups
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Invoke(InvokeRequest request)
   at Amazon.JSII.Runtime.Services.Client.Invoke(ObjectReference objectReference, String method, Object[] arguments)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<>c__DisplayClass17_0`1.<InvokeInstanceMethod>b__1(IClient client, Object[] args)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceMethod[T](Type[] parameterTypes, Object[] arguments, String methodName)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceVoidMethod(Type[] parameterTypes, Object[] arguments, String methodName)
   at Amazon.CDK.AWS.ElasticLoadBalancingV2.ApplicationListener.AddTargetGroups(String id, IAddApplicationTargetGroupsProps props)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Invoke(InvokeRequest request)
   at Amazon.JSII.Runtime.Services.Client.Invoke(ObjectReference objectReference, String method, Object[] arguments)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<>c__DisplayClass17_0`1.<InvokeInstanceMethod>b__1(IClient client, Object[] args)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceMethod[T](Type[] parameterTypes, Object[] arguments, String methodName)
   at Amazon.CDK.AWS.ElasticLoadBalancingV2.ApplicationListener.AddTargets(String id, IAddApplicationTargetsProps props)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Invoke(InvokeRequest request)
   at Amazon.JSII.Runtime.Services.Client.Invoke(ObjectReference objectReference, String method, Object[] arguments)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<>c__DisplayClass17_0`1.<InvokeInstanceMethod>b__1(IClient client, Object[] args)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceMethod[T](Type[] parameterTypes, Object[] arguments, String methodName)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceVoidMethod(Type[] parameterTypes, Object[] arguments, String methodName)
   at Amazon.CDK.AWS.ECS.BaseService.RegisterLoadBalancerTargets(IEcsTarget[] targets)
   at Cdk.CdkStack..ctor(Construct scope, String id, IStackProps props) in ...\cdk\Sources\CdkStack.cs:line 61
   at Cdk.Program.Main() in ...\cdk\Sources\Program.cs:line 11
Subprocess exited with error 3762504530
@aetos382 aetos382 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 7, 2021
@github-actions github-actions bot added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Dec 7, 2021
@NGL321 NGL321 added the p2 label Dec 8, 2021
@madeline-k
Copy link
Contributor

@aetos382 thanks for opening this issue, and providing repro steps. I was able to reproduce this issue, and I think it may be a regression.

@njlynch
Copy link
Contributor

njlynch commented Jan 14, 2022

For what it's worth, here is an equivalent stack definition in Typescript:

import * as cdk from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';

export class Issue17876 extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const vpc = new ec2.Vpc(this, 'MyVpc');
    const cluster = new ecs.Cluster(this, 'EcsCluster', { vpc });

    const taskDefinition = new ecs.FargateTaskDefinition(this, 'FargateTaskDef', {
      cpu: 256,
      memoryLimitMiB: 512,
    });

    const container = taskDefinition.addContainer('container', {
      image: ecs.ContainerImage.fromRegistry('nginx'),
      portMappings: [{ containerPort: 80 }],
    });

    const service = new ecs.FargateService(this, 'FargateService', {
      cluster,
      taskDefinition,
    });

    const loadBalancer = new elbv2.ApplicationLoadBalancer(this, 'LoadBalancer', { vpc });

    service.registerLoadBalancerTargets({
      containerName: container.containerName,
      containerPort: container.containerPort,
      newTargetGroupId: 'targetGroup',
      listener: ecs.ListenerConfig.applicationListener(new elbv2.ApplicationListener(this, 'AlbListener', {
        loadBalancer,
        protocol: elbv2.ApplicationProtocol.HTTP,
      })),
    });
  }
}

I can't reproduce the above error in Typescript using the above (with the appropriate CDK versions). That certainly points the finger to a quirk of jsii. I think the culprit is #17328, which changed a lot of code to avoid deprecation warnings within the CDK itself. It changed a lot of explicit property passing to the spread operator (...).

Here's the code today:

this.addTargetGroups(id, {
targetGroups: [group],
...props,
});

Here's the code prior to the change:

this.addTargetGroups(id, {
conditions: props.conditions,
hostHeader: props.hostHeader,
pathPattern: props.pathPattern,
pathPatterns: props.pathPatterns,
priority: props.priority,
targetGroups: [group],
});

RomainMuller added a commit to aws/jsii that referenced this issue Jan 14, 2022
The jsii kernel needs to attach metadata to instances that are sent
across the process boundary. While these properties use symbol names to
eliminate the risk for collisions with user-defined properties, they
were inadvertently set as `enumerable`, causing those to show in outputs
of `JSON.stringify` and to be copied over as part of spat expressions
(e.g: `{...obj}`), which resulted in the new value sharing the same
identity as the previous one when sent over the wire.

Caused: aws/aws-cdk#17876
@RomainMuller
Copy link
Contributor

We identified the cause for this issue (see aws/jsii#3339 for more details).

The jsii runtime bug has been there virtually forever, but CDK did not previously trigger that, so it went unnoticed.

Once aws/jsii#3339 is released, ensuring the updated version of the jsii runtime library should be enough to get the problem fixed (no need to wait for a CDK release).

mergify bot pushed a commit to aws/jsii that referenced this issue Jan 17, 2022
The jsii kernel needs to attach metadata to instances that are sent
across the process boundary. While these properties use symbol names to
eliminate the risk for collisions with user-defined properties, they
were inadvertently set as `enumerable`, causing those to show in outputs
of `JSON.stringify` and to be copied over as part of spat expressions
(e.g: `{...obj}`), which resulted in the new value sharing the same
identity as the previous one when sent over the wire.

Caused: aws/aws-cdk#17876



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
@madeline-k madeline-k added jsii This issue originates in jsii, or this feature must be implemented in jsii. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 18, 2022
@madeline-k madeline-k removed their assignment Jan 18, 2022
@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. jsii This issue originates in jsii, or this feature must be implemented in jsii. p2
Projects
None yet
Development

No branches or pull requests

5 participants