# How to stopconsumer properly

**URL:** <https://forum.djangoproject.com/t/how-to-stopconsumer-properly/19726>\
**Category:** Async/Channels\
**Created:** [March 22, 2023, 9:27pm UTC](https://forum.djangoproject.com/t/how-to-stopconsumer-properly/19726 "2023-03-22T21:27:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thalesmendonca](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/thalesmendonca/32/12848_2.png) [@thalesmendonca](https://forum.djangoproject.com/u/thalesmendonca)\
**Post date:** [March 22, 2023, 9:27pm UTC](https://forum.djangoproject.com/t/how-to-stopconsumer-properly/19726/1 "2023-03-22T21:27:00Z")

</div>

I’m having trouble with my websocket stability and I’m afraid it’s because I’m not shutting down everything before calling StopConsumer(). So, when I raise StopConsumer() in websocket\_disconnect() will my async websocket\_receive() stop?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 22, 2023, 10:45pm UTC](https://forum.djangoproject.com/t/how-to-stopconsumer-properly/19726/2 "2023-03-22T22:45:28Z")

</div>

Can you be more specific and provide more details about what exactly is happening here?

Note the docs for [`Closing Consumers`](https://channels.readthedocs.io/en/stable/topics/consumers.html?highlight=stopconsumer#closing-consumers):

> Once you have finished doing your post-disconnect cleanup, you need to raise `channels.exceptions.StopConsumer` to halt the ASGI application cleanly and let the server clean it up.

This implies that you raise it _after_ you have finished _all_ of your work related to the disconnect.

However, also note that it’s already raised in websocket\_disconnect - are you overriding that function?
