# Fix interleaved subscription operations \(\#52369\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 06fabec0c108f40bfa257d84942b42c1590966a8

Requested commit: 06fabec0c108f40bfa257d84942b42c1590966a8

Commit: 06fabec0c108f40bfa257d84942b42c1590966a8

Tree: fc2ed92a1d48b82e4baadaa2fc9f489342522357

Author: Mikayla Maki

Committer: GitHub

## Message

```
Fix interleaved subscription operations (#52369)

## Context

Since https://github.com/zed-industries/zed/pull/52232/, there have been
a lot of problems related to panels randomly hiding and showing
themselves. However, the code in that PR is pretty innocuous. It
shouldn't be having that kind of effect. However, it turns out there's a
bug in how GPUI subscriptions work that caused there to be orphaned
observe callbacks firing spuriously. The core sequence is captured in
`test_unsubscribe_during_callback_with_insert`, essentially you have to
have two observers on the same item (`SettingsStore`, in this case),
that both drop themselves. If the first observer _adds_ a callback onto
the _same item_, then the second observer will never successfully drop
itself.

While in there, I also fixed an unrelated bug that @maxbrunsfeld noticed
where if you have two callbacks on the same item, and an earlier
callback drops a later one, then the second callback will spuriously
fire.

I also added a few extra smoke tests to the subscription code, and a
test capturing the observed bug at the workspace level.

## Self-Review Checklist

<!-- Check before requesting review: -->
- [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

Release Notes:

- N/A

---------

Co-authored-by: max <max@zed.dev>
```

## Parents

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

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