atlantis icon indicating copy to clipboard operation
atlantis copied to clipboard

Atlantis fails to unlock if PR declined mid-plan

Open ryan-dyer-sp opened this issue 4 years ago • 13 comments

Atlantis appears to have an issue where if a PR is declined while a plan is in flight, the locks are not properly removed. Or perhaps they are being removed at the time of the declining, but as the plan is not aborted, new locks are perhaps being created. Either way I now have to go through the UI and turn off nearly 100 locks for a PR which is awful.

ryan-dyer-sp avatar Sep 29 '20 15:09 ryan-dyer-sp

You might be able to reopen the PR and close it again to unlock (after plans) as a workaround..

mwarkentin avatar Sep 29 '20 21:09 mwarkentin

Unfortunately, BitBucket does not allow you to reopen a declined PR, removing that as a workaround.

iresprite avatar Nov 30 '20 16:11 iresprite

when you close a PR in github the locks are removed. I use 0.15.0 and this works, what version @ryan-dyer-sp are you using?

jamengual avatar Feb 10 '21 21:02 jamengual

Yes Atlantis will typically remove the locks when you close a PR. However, if atlantis is in the middle of performing a plan operation when the closing of the PR occurs, not all locks are cleaned up. We have seen this multiple times when someone submits a PR which result in 100s of project changes. They realize their mistake and close the PR while the plan is still in flight. And we're left with 100s of locks in the atlantis.db with no way to remove them. If #1393 were fixed, that would provide a workaround for many ways in which PRs can be closed but the locks still exist in the DB.

ryan-dyer-sp avatar Feb 10 '21 21:02 ryan-dyer-sp

so your problem is only with atlantis locks but somehow you do not have issues with remote state locks in terraform? if I cancel an apply on terraform I end with the same problem.

jamengual avatar Feb 10 '21 21:02 jamengual

No, my problem is not only with atlantis locks. The only problem I have I cant solve in less than a few seconds with some other workaround is with atlantis locks. The UI is fine if you only need to delete a lock or two. When you have a PR with over a hundred. Not so much. And when you have multiple PRs with dozens of locks and you only need to unlock those for a single PR. deleting the entire db, cleaning up the working dir, and restarting atlantis does not make for a decent workaround. Even though we've had to resort to it multiple times now.

ryan-dyer-sp avatar Feb 10 '21 22:02 ryan-dyer-sp

and I'm guessing the unlock comment command does not work for you either?

jamengual avatar Feb 10 '21 23:02 jamengual

I'm asking question to completely understand the issue and see how we could help you

jamengual avatar Feb 11 '21 00:02 jamengual

This ticket was written before the unlock command existed. And the unlock command doesnt work once a PR is closed (#1393). As we use bitbucket, you cant reopen a PR once it is Declined in order to issue an unlock.

ryan-dyer-sp avatar Feb 11 '21 00:02 ryan-dyer-sp

If #1393 were addressed, the issue with this ticket would be less of an issue as there would be a sufficient enough workaround that I wouldnt care about the various ways a PR can be closed and no way to unlock all of its projects other than through the UI.

ryan-dyer-sp avatar Feb 11 '21 00:02 ryan-dyer-sp

do you think you can look into sending a PR for this?

jamengual avatar Feb 11 '21 00:02 jamengual

@ryan-dyer-sp @jamengual I ran into this issue this past week. I can take a crack at it.

The issue is that the two "events" are unaware of each other. A command can come through either because of a GH command or PR closing. At that point in time it will execute and clean up any locks, however since a plan/apply is still running it will create more locks after thus the race condition.

There are two ways to solve this:

  1. Emit a signal to project_command_pool_executor to exit early prior to cleaning up locks
  2. Wait on firing the clean up locks event until the plan/apply finishes

GenPage avatar Apr 19 '21 18:04 GenPage

Or perhaps just allow the unlock command to work on closed PRs?

starkpister avatar Jul 19 '22 18:07 starkpister

@starkpister I'd imagine we'd be open to a PR for the unlock command to work on closed PRs. PRs welcome.

nitrocode avatar Nov 19 '22 15:11 nitrocode

As great a solution as that might have been 6 months ago, we have since switched to a different method for deploying our terraform because of this bug.

starkpister avatar Nov 19 '22 19:11 starkpister

Apologies. This project is maintained by open source developers and we welcome new changes to improve the project.

I think allowing the unlock command on closed PRs would be sufficient here.

nitrocode avatar Nov 19 '22 20:11 nitrocode

Submitted a PR to allow commenting unlock on closed PRs https://github.com/runatlantis/atlantis/pull/2916 as suggested.

johanneswuerbach avatar Jan 04 '23 10:01 johanneswuerbach