Skip to content

Commit

Permalink
add validation when tcpIdleTimeout is smaller than 1 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
mazyu36 committed Oct 8, 2024
1 parent 8163508 commit bef3d2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ export class NetworkListener extends BaseListener implements INetworkListener {
}

if (props.tcpIdleTimeout !== undefined && !Token.isUnresolved(props.tcpIdleTimeout)) {
if (props.tcpIdleTimeout.toMilliseconds() < Duration.seconds(1).toMilliseconds()) {
throw new Error(`\`tcpIdleTimeout\` must be between 60 and 6000 seconds, got ${props.tcpIdleTimeout.toMilliseconds()} milliseconds.`);
}

const tcpIdleTimeoutSeconds = props.tcpIdleTimeout.toSeconds();

if (proto === Protocol.UDP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,23 @@ describe('tests', () => {
}).toThrow('\`tcpIdleTimeout\` cannot be set when `protocol` is `Protocol.UDP`.');
});

test('throws when tcpIdleTimeout is smaller than 1 second.', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
const group = new elbv2.NetworkTargetGroup(stack, 'TargetGroup', { vpc, port: 80 });
const lb = new elbv2.NetworkLoadBalancer(stack, 'LB', { vpc });

// WHEN
expect(() => {
lb.addListener('Listener1', {
port: 80,
defaultAction: elbv2.NetworkListenerAction.forward([group]),
tcpIdleTimeout: cdk.Duration.millis(1),
});
}).toThrow('\`tcpIdleTimeout\` must be between 60 and 6000 seconds, got 1 milliseconds.');
});

test.each([1, 10000])('throws when tcpIdleTimeout is invalid seconds, got: %d seconds', (tcpIdleTimeoutSeconds) => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit bef3d2c

Please sign in to comment.