-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[CLI] cdk deploy keeps calling describeStackEvents() for ~10 minutes after stack update #9470
Comments
Here is the sequence of debug output that occurs at the time the stack update finishes. After this the describeStackEvents() go on.
|
@kennu what's the stack status? does it end with at a cursory glance, it looks like the deploy status is not being classified as terminal so the CLI continues polling the stack until a terminal status is reached or it times out and gives up. |
I think the stack final status is always |
To my understanding, this is the recursive step that keeps calling
I'm not quite sure about the logic there, but it seems like it just keeps iterating more and more events in my stack(s). |
If it's true that the paging token is not properly retained between polls, that would be pretty bad. |
I think that the token is retained, but I just have a lot of events in that stack. So it takes a long time to iterate through all of them. |
I double checked by adding a console.log() of every stack event that AWS CDK scans through. It really iterates all the stack events from today all the way back to 2019-04-07 when the stack was created. Unless I misunderstand something, the whole logic of StackActivityMonitor.readEvents() is flawed. It will always scan through the entire stack event history, which keeps growing forever and making deployments slower and slower. This is the last entry scanned before
|
Yep. Turns out we are accidentally quadratic! |
The stack monitor used to read all stack events on every tick (every 1-5 seconds). That's right, every 5 seconds it would page through all events that had ever happened to the stack, only to get to the last page to see if there were new events. We were quadratic in our `DescribeStackEvents` API call. This behavior has probably contributed to our users getting throttled by CloudFormation in the past, and only really shows pathological behavior on stacks with a long history (which we ourselves don't routinely manage using `cdk deploy`), which is why it had eluded detection for so long. The fix is to remember the token of the last page between calls, so that we don't have to read through all pages just to get to the last one. Fixes #9470.
…9795) The stack monitor used to read all stack events on every tick (every 1-5 seconds). That's right, every 5 seconds it would page through all events that had ever happened to the stack, only to get to the last page to see if there were new events. We were quadratic in our `DescribeStackEvents` API call. This behavior has probably contributed to our users getting throttled by CloudFormation in the past, and only really shows pathological behavior on stacks with a long history (which we ourselves don't routinely manage using `cdk deploy`), which is why it had eluded detection for so long. The fix is to remember the token of the last page between calls, so that we don't have to read through all pages just to get to the last one. Fixes #9470. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…ws#9795) The stack monitor used to read all stack events on every tick (every 1-5 seconds). That's right, every 5 seconds it would page through all events that had ever happened to the stack, only to get to the last page to see if there were new events. We were quadratic in our `DescribeStackEvents` API call. This behavior has probably contributed to our users getting throttled by CloudFormation in the past, and only really shows pathological behavior on stacks with a long history (which we ourselves don't routinely manage using `cdk deploy`), which is why it had eluded detection for so long. The fix is to remember the token of the last page between calls, so that we don't have to read through all pages just to get to the last one. Fixes aws#9470. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
In #9795, I was under the impression that the `DescribeStackEvents` would list events in chronological order. This was a misunderstanding resulting from not reading the documentation-- in fact, the events are returned in reverse chronological order. The paging logic was therefore wrong and the events would be fed into the activity printer in the wrong order, leading to incorrect progress reporting. This is a critical bug and must be fixed immediately! While I was in there, fixed two other paper cuts around the printer at the same time: - Events occurring near the start of the monitor would be missed. This was because time-based filtering would be employed based on the client machine's local clock, which might be out of sync with the remote clock. Use the server's clock instead, by using the `CreationTime` of the ChangeSet as the start time. - Events occurring near the end of the monitor would be missed. This was because `DescribeStackStatus` might return a completion state before the monitor had polled the events that led up to the completion. Fix by doing a final poll after the stop call has been received, so we are guaranteed to have seen all events. The actual claim in that PR was incorrect. We were *not* quadratic (we wouldn't list all pages on every tick), we were just more linear than necessary (we *would* list all pages on the *first* tick... which is still a lot). The current PR properly fixes the issue by stopping paging not just if we've already seen the events, but also if the events are starting to fall outside the time window we are interested in. This *actually* fixes #9470. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
AWS CDK
cdk deploy
keeps calling describeStackEvents() for about 10 minutes after the CloudFormation stack has been successfully updated. It seems that CDK iterates through the entire event history of the stack in 5 second intervals. This makes thecdk deploy
command take a very long time.During the delay AWS CDK appears to be stuck in the "creating CloudFormation changeset" phase. In reality it has already created the changeset and applied it to the CloudFormation stack.
Reproduction Steps
You might need a CloudFormation stack that has a lot of event history to notice that AWS CDK iterates through all of them, causing the long delay.
You can see the
describeStackEvents()
iteration in debug output by usingcdk deploy -v -v -v
. It will keep showing entries like this (with different NextToken as it progresses):What did you expect to happen?
cdk deploy
should finish in about 3 minutes.What actually happened?
cdk deploy
takes 14 minutes to complete.Environment
Other
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: