# Logs 'Job exception: unexpected return' error

**URL:** https://meta.discourse.org/t/logs-job-exception-unexpected-return-error/299963
**Category:** Bug
**Tags:** chat
**Created:** [March 19, 2024, 10:12am UTC](https://meta.discourse.org/t/logs-job-exception-unexpected-return-error/299963 "2024-03-19T10:12:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [March 19, 2024, 10:12am UTC](https://meta.discourse.org/t/logs-job-exception-unexpected-return-error/299963/1 "2024-03-19T10:12:55Z")

</div>

Hello 👋

I’ve noticed this error in `/logs`. Which is probably related with this commit: [PERF: defer loading channels (#26155) · discourse/discourse@bbb8595 · GitHub](https://github.com/discourse/discourse/commit/bbb8595107efce1653fde5d9468df077d529b6ca)

info

```plaintext
Job exception: unexpected return

```

> **backtrace**
>
> ```plaintext
> /var/www/discourse/plugins/chat/app/services/chat/list_channel_messages.rb:177:in `block in update_user_last_channel'
> /var/www/discourse/lib/scheduler/defer.rb:115:in `block in do_work'
> rails_multisite-6.0.0/lib/rails_multisite/connection_management/null_instance.rb:49:in `with_connection'
> rails_multisite-6.0.0/lib/rails_multisite/connection_management.rb:21:in `with_connection'
> /var/www/discourse/lib/scheduler/defer.rb:109:in `do_work'
> /var/www/discourse/lib/scheduler/defer.rb:97:in `block (2 levels) in start_thread'
> 
> ```

* * *

Few other info:

- The thread function is disabled now on my site.

- I’ve noticed the error shows up in `/logs` when I open the chat and it jump to the last visited channel. When I go back to the channel list and close the chat, the error won’t show up in `/logs` after open the chat.

Repro:

1. Open chat and go to a channel
2. Close chat
3. Open chat again which will jump to the last visited channel

The error should appear in `/logs`.

Edit: Seems it sometimes happens also when I go to a channel from channel list.  
Edit 2: It happens when I go to the last visited channel from channel list.

Thanks 🙂

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [March 20, 2024, 9:49am UTC](https://meta.discourse.org/t/logs-job-exception-unexpected-return-error/299963/3 "2024-03-20T09:49:46Z")

</div>

Good catch @Don thanks. Will be fixed in [FIX: do not use return in block by jjaffeux · Pull Request #26260 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/26260)

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [March 20, 2024, 9:49am UTC](https://meta.discourse.org/t/logs-job-exception-unexpected-return-error/299963/4 "2024-03-20T09:49:48Z")

</div>


