Skip to content

Commit

Permalink
[MIRROR] Fixes race condition in Life() [MDB IGNORE] (#25279)
Browse files Browse the repository at this point in the history
* Fixes race condition in Life() (#79934)

## About The Pull Request

This fixes the following runtime by adding sanity checking for
`reagents`:

![image](https://github.com/tgstation/tgstation/assets/13398309/6e83b958-5144-4822-aed6-7ee4bb3d779b)

It can be null, which I presume is from the mob being qdeleted in the
middle of a `Life()` tick but I'm not 100% sure of that.

The check for `QDELETED(src)` happens after `handle_organs()` and
`handle_dead_metabolism()`, which there was no protection against there
being a null reagent var for either of those procs.

I was debating moving the order of the procs around, but I decided
against it because I think it may be this way for a reason
(`organ.on_death()` gets called in `handle_organs()`), plus again I'm
not 100% sure that the `reagents` is being nulled from qdeletion.

## Why It's Good For The Game

Fixes a bug that kept coming up in CI

## Changelog

:cl:
fix: fixed a runtime in handle_dead_metabolism()
/:cl:

---------

Co-authored-by: MrMelbert <51863163+MrMelbert@ users.noreply.github.com>

* Fixes race condition in Life()

---------

Co-authored-by: Bloop <[email protected]>
Co-authored-by: MrMelbert <51863163+MrMelbert@ users.noreply.github.com>
  • Loading branch information
3 people authored and FFMirrorBot committed Nov 27, 2023
1 parent 3aa9bb6 commit cec8664
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions code/modules/mob/living/carbon/life.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

if(HAS_TRAIT(src, TRAIT_STASIS))
. = ..()
reagents.handle_stasis_chems(src, seconds_per_tick, times_fired)
reagents?.handle_stasis_chems(src, seconds_per_tick, times_fired)
else
//Reagent processing needs to come before breathing, to prevent edge cases.
handle_dead_metabolization(seconds_per_tick, times_fired) //Dead metabolization first since it can modify life metabolization.
Expand Down Expand Up @@ -488,7 +488,7 @@

/mob/living/carbon/proc/handle_organs(seconds_per_tick, times_fired)
if(stat == DEAD)
if(reagents.has_reagent(/datum/reagent/toxin/formaldehyde, 1) || reagents.has_reagent(/datum/reagent/cryostylane)) // No organ decay if the body contains formaldehyde.
if(reagents && (reagents.has_reagent(/datum/reagent/toxin/formaldehyde, 1) || reagents.has_reagent(/datum/reagent/cryostylane))) // No organ decay if the body contains formaldehyde.
return
for(var/obj/item/organ/internal/organ in organs)
// On-death is where organ decay is handled
Expand Down Expand Up @@ -569,9 +569,9 @@
* - times_fired: The number of times SSmobs has ticked.
*/
/mob/living/carbon/proc/handle_dead_metabolization(seconds_per_tick, times_fired)
if (stat != DEAD)
if(stat != DEAD)
return
reagents.metabolize(src, seconds_per_tick, times_fired, can_overdose = TRUE, liverless = TRUE, dead = TRUE) // Your liver doesn't work while you're dead.
reagents?.metabolize(src, seconds_per_tick, times_fired, can_overdose = TRUE, liverless = TRUE, dead = TRUE) // Your liver doesn't work while you're dead.

/// Base carbon environment handler, adds natural stabilization
/mob/living/carbon/handle_environment(datum/gas_mixture/environment, seconds_per_tick, times_fired)
Expand Down

0 comments on commit cec8664

Please sign in to comment.