Skip to content

Error: foreign key constraint failed when running cargo shuttle delete #561

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

Closed
sd2k opened this issue Jan 2, 2023 · 3 comments · Fixed by #619
Closed

Error: foreign key constraint failed when running cargo shuttle delete #561

sd2k opened this issue Jan 2, 2023 · 3 comments · Fixed by #619

Comments

@sd2k
Copy link
Contributor

sd2k commented Jan 2, 2023

I'm getting the following error when trying to run cargo shuttle delete:

❯ cargo shuttle delete
Error: 500 Internal Server Error
message: Persistence failure: Database error: error returned from database: (code: 787) FOREIGN KEY constraint failed

I haven't managed to successfully deploy anything yet (due to #527, I think?) so this might be an invalid command, but the error message could be nicer 🙂

@oddgrd
Copy link
Contributor

oddgrd commented Jan 2, 2023

Hey Ben! Yeah, this one's not very kind on the eyes. We've known about this bug but must have forgotten to open an issue for it, so thanks for that!

The delete op does actually work (in that it stops the running deployment), but I believe the root of this bug is that we ignore the error in delete_deployments_by_service_id. This means the delete_service handler will proceed with stopping the deployment despite getting a FK error. When we then try to delete the service we'll get the FK error again, and since we don't ignore it here a 500 error will be returned from the handler (but the service will have already stopped).

For reference, this is the deployer handler called by cargo shuttle delete: https://github.com/shuttle-hq/shuttle/blob/main/deployer/src/handlers/mod.rs#L253

@oddgrd oddgrd added the bug label Jan 2, 2023
@oddgrd oddgrd self-assigned this Jan 23, 2023
@InfernapeXavier
Copy link

Hey @oddgrd I ran into the same error today trying to stop my deployment. I can confirm that it definitely is still running despite me getting this error.

@oddgrd
Copy link
Contributor

oddgrd commented Feb 6, 2023

Ah, thanks! Yes, it does seem there is an issue with stopping deployments as well, and currently you'd need to do a cargo shuttle project rm to stop it. We've resolved this in a major refactor of our backend, but it may be a while until it gets merged. In other words, fixing the actual stoppage is out of scope for this issue.

An update on what we want to solve this bug (the FK error): we don't actually want to delete anything, rather we want to stop the service and change the state of the related tables to Stopped. We could also change the name of the cli-command (and associated functions) to stop rather than delete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants