# Fix hang detection crash when foreground stats are missing \(\#58464\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/b76e0bc9ddda3ead9e3257dc594b84c9bc594a29)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: b76e0bc9ddda3ead9e3257dc594b84c9bc594a29

Requested commit: b76e0bc9ddda3ead9e3257dc594b84c9bc594a29

Commit: b76e0bc9ddda3ead9e3257dc594b84c9bc594a29

Tree: f17c8f02e596cdb01e47688d348ebbb69cc79563

Author: Anthony Eid

Committer: GitHub

## Message

```
Fix hang detection crash when foreground stats are missing (#58464)

Register the foreground thread with the GPUI profiler before starting
hang detection, so foreground task statistics are available when the
hang detection thread samples profiler data.

cc: @yara-blue I choose to leave the expect statements because it seems
like an invariant that we should uphold. Let me know if you would rather
have early returns and telemetry if they're hit

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes FR-58

Release Notes:

- Fixed a crash in hang detection when foreground thread statistics were
missing.

---------

Co-authored-by: Yara <git@yara.blue>
```

## Parents

- [ca0fd8d4e16e0e2687058552a9545625f00e0fb3](https://git.cafe/gitcafe/zed/commit/ca0fd8d4e16e0e2687058552a9545625f00e0fb3?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/b76e0bc9ddda3ead9e3257dc594b84c9bc594a29?format=markdown)
