Skip to content

Redis trigger: spawn a task for each message - #3809

Draft
itowlson wants to merge 1 commit into
spinframework:mainfrom
itowlson:redis-trigger-spawn-spawn-spawn
Draft

itowlson wants to merge 1 commit into
spinframework:mainfrom
itowlson:redis-trigger-spawn-spawn-spawn

Conversation

@itowlson

Copy link
Copy Markdown
Contributor

I admit to being not quite sure about this one.

My reading of the Redis trigger is that each subscription noms linearly through its message stream: next, handle, next, handle, next. Although this is all async, it seems like it is all in one waves hands causality. This causes two problems:

  1. If something goes wrong in a message handler, the subscription loop dies (and takes down the app with it, because we do not want an app that seems to be working but is actually ignoring some of its subscriptions).
  2. If the handler is slow, messages that arrive close together can get backed up (not that a Redis queue handler is likely to be super time sensitive, but still)

Again, to be clear, I may be misunderstanding things. Redis trigger experts, correct me if I am.

This PR proposes (tentatively, because see above re uncertainty) that we spawn a new Tokio task for each incoming message and its handler. The spawn returns promptly even if the handler takes a long time to run, so we can receive messages with a bit more throughput; and the task means the handler gets its own stack, so an error or panic doesn't propagate out and bring down the loop.

There is some modest ceremony involved in making the handler spawnable, but really this PR is "line 185 plus hangers on."

Needless to say, I'm entirely open to being told that I'm missing something, and that this PR is unecessary or goes in the wrong direction...

Signed-off-by: itowlson <ivan.towlson@fermyon.com>
@itowlson
itowlson requested a review from a team November 24, 2026 02:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant