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: prevent creating duplicate machine ids #116

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

goller
Copy link
Contributor

@goller goller commented Nov 5, 2024

We saw the same machine id created more than one time. This caused an issue where the cli would not be able to connect to the correct machine.

We now wait for the instance to be created.
We don't care about what state the instance is in
only that it has been handled by AWS.

We believe duplication would happen when the scheduleTask would finish quickly, receive the next update from the API, but without AWS reporting the machine as pending.

Note: another way we could fix this is to use the cache of changes as we did with volumes.

We saw the same machine id created more than one time.
This caused an issue where the cli would not be able
to connect to the correct machine.

We now wait for the instance to be created.
We don't care about what state the instance is in
only that it has been handled by AWS.

We believe duplication would happen when the scheduleTask
would finish quickly, receive the next update from the API,
but without AWS reporting the machine as pending.

Co-authored-by: Billy Batista <[email protected]>
Signed-off-by: Chris Goller <[email protected]>
@goller
Copy link
Contributor Author

goller commented Nov 5, 2024

@goller
Copy link
Contributor Author

goller commented Nov 5, 2024

Fixes DEP-1943

src/utils/aws.ts Outdated

// We are waiting for the instance to exist because we are blocking scheduleTask
// from starting another task with the same machine ID until this one completes.
while (!instanceCreated) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a sleep otherwise this is a tight loop of API requests

Possibly better and API aware, the AWS SDK should have a wait for method I believe, similar to the Go SDK https://aws.amazon.com/blogs/developer/waiters-in-modular-aws-sdk-for-javascript/

Copy link
Member

@jacobwgillespie jacobwgillespie Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the one, something like https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ec2/Variable/waitForInstanceExists/:

const maxWaitTime = 30 // seconds
await waitForInstanceExists({client, maxWaitTime}, {InstanceIds: [instanceID]})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in ffc5a68

Signed-off-by: Chris Goller <[email protected]>
Copy link
Member

@jacobwgillespie jacobwgillespie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@goller goller merged commit 5ef57c3 into main Nov 5, 2024
2 checks passed
@goller goller deleted the fix/multiple-instances-created branch November 5, 2024 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants