# Cancel build sometimes doesn't cancel all jobs

**URL:** <https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555>\
**Category:** Travis CI Discussions & Feedback\
**Created:** [February 6, 2023, 3:01am UTC](https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555 "2023-02-06T03:01:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sih4sing5hong5](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/sih4sing5hong5/32/8483_2.png) [@sih4sing5hong5](https://travis-ci.community/u/sih4sing5hong5)\
**Post date:** [February 6, 2023, 3:01am UTC](https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555/1 "2023-02-06T03:01:29Z")

</div>

I canceled my builds in my private repo. There are 6 jobs in every build.  
Usually I cancel a build, the third job and fourth job were not cancel.

What infomation can I provide?

Thanks, Aray.

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [February 10, 2023, 3:45pm UTC](https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555/2 "2023-02-10T15:45:41Z")

</div>

Hi @sih4sing5hong5,

Is this still occurring?

---

<div class="post-metadata">

**Author:** ![sih4sing5hong5](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/sih4sing5hong5/32/8483_2.png) [@sih4sing5hong5](https://travis-ci.community/u/sih4sing5hong5)\
**Post date:** [February 15, 2023, 12:35am UTC](https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555/3 "2023-02-15T00:35:17Z")

</div>

It worked normally yesterday. I tried three builds 🙂

> Usually I cancel a build, the third job and fourth job were not cancel.  
> I tried over 10 builds 2 weeks ago.

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [February 20, 2023, 4:04pm UTC](https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555/4 "2023-02-20T16:04:40Z")

</div>

Hi @sih4sing5hong5,

Great to hear!

---

<div class="post-metadata">

**Author:** ![sih4sing5hong5](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/sih4sing5hong5/32/8483_2.png) [@sih4sing5hong5](https://travis-ci.community/u/sih4sing5hong5)\
**Post date:** [March 23, 2023, 7:57am UTC](https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555/5 "2023-03-23T07:57:31Z")

</div>

It’s occurring, this time is in our [public repo](https://app.travis-ci.com/github/i3thuan5/multiple-databases-backup/builds/261707378).

This repo has 5 concurrent jobs.

The steps as below:

1. Check there is no running job.
2. `git push` and cancel the build within 5 seconds.
3. Restart the first jobs.
4. The 6th, 8th, 9th and 10th jobs is running. They don’t have running after finishing.

It may be a race-condition.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [April 20, 2023, 10:03pm UTC](https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555/6 "2023-04-20T22:03:26Z")

</div>

Hey @sih4sing5hong5,

I’m thinking the best way to solve this is to run a chunk of user code before the stock installation logic occurs.

As it is now, stock installation logic (platform install, build addons) run before any user-supplied code gets control. As a consequence, if that logic doesn’t quite fit the needs or something goes wrong with it, all a user can do is ditch it altogether.

Alternatively, you can check at job start if it needs to be run and quit it early (with `travis_terminate` or by making the rest of your logic a no-op if you need further automatic steps like saving the cache to run) if it doesn’t. Currently, you can only do this as early as at `before_install`.

This wouldn’t be an issue on Travis CI Enterprise, because this would allow you to build on your own worker machines of however much power you need. If you need to run 50 jobs in parallel every build and lots and lots of builds per day, which you seem to be a large-scale enough consumer for that, then that might be something you want to look into.

For the race-condition, I’ll look over your `.travis.yml` carefully.

Cheers,  
Montana Mendy

---

<div class="post-metadata">

**Author:** ![sih4sing5hong5](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/sih4sing5hong5/32/8483_2.png) [@sih4sing5hong5](https://travis-ci.community/u/sih4sing5hong5)\
**Post date:** [April 24, 2023, 12:59am UTC](https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555/7 "2023-04-24T00:59:39Z")

</div>

Thanks, I will try it 🙂

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [April 27, 2023, 6:04pm UTC](https://travis-ci.community/t/cancel-build-sometimes-doesnt-cancel-all-jobs/13555/8 "2023-04-27T18:04:53Z")

</div>

Hi @sih4sing5hong5,

No problem!
