I have a program, which if initiated and then terminated, needs to perform some cleanup operations before the termination. I am using such a program in a CircleCI Job. The program currently reads for SIGKILL and SIGINT. What signal does CircleCI close the ongoing processes with when a job is canceled? Reading on the above two signals does not cause program to perform cleanups
My interpretation of what happens when a workflow is cancelled in CCI is that a
kill -9 signal is sent to it, which seems to match up with one of your expectations.
If that’s what happens (and I haven’t gone through to prove it empirically yet nor can I find specific documentation about what’s being done) then there’s nothing you can do.
Instead, you need to make it so that the program in question can be reentrant. Because of the ephemeral nature of the compute resources in CCI this is sometimes not that big a deal but if you’re doing coordination work (like I do for my deployments, for instance) then it can get tricky. My current solution is to let humans clean it up and simply tell them noisily that I’m in an unrecoverable state, but that’s not great.
A better solution would be to have CCI start to send something like SIGTERM or maybe even better send SIGTERM by default but allow us to configure what gets sent to the process before until, after some grace period,
SIGKILL gets fallen back to.
Hope that helps.