elsa-workflows / elsa-workflows/elsa-core

Graceful Shutdown

Open
#6,401 5 comments 3 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

Currently, when an **ASP.NET Core** application running **Elsa Workflows** shuts down, it may terminate workflows that are still executing. This can lead to inconsistencies, especially when workflows interact with external systems, databases, or queues.

This feature request proposes a **graceful shutdown mechanism** that allows active workflows to **complete up to a commit point** before the application stops while ensuring that **no new workflows are started during the shutdown phase**.

### **Use Case & Requirements**
1. **Ongoing Workflows Complete Before Shutdown**
- Elsa should detect when the application is shutting down.
- Workflows that are currently executing should be allowed to **finish their current activity but not proceed beyond a commit point**.

2. **New Workloads Should Not Be Accepted**
- MassTransit consumers should **stop accepting new messages** while allowing in-flight messages to complete.
- Background jobs (e.g., **Quartz.NET, Hangfire**) should **pause scheduling new work**.
- HTTP API endpoints for starting new workflows should **return a service unavailable response** or **queue execution until restart**.

3. **Extensibility for 3rd-Party Modules**
- Introduce a **global shutdown notification event** that extensions can hook into.
- Provide an interface like **`IShutdownHandler`** that modules can implement to clean up background tasks and other resources.

### **Proposed Implementation (by chatGPT)**
- Introduce a **shutdown token** or **state flag** that Elsa’s execution engine checks before starting new activities.
- Implement a **shutdown event dispatcher** that:
- Stops MassTransit consumers.
- Pauses job schedulers.
- Notifies registered `IShutdownHandler` implementations.
- Ensure the `WorkflowRunner` (or equivalent execution engine) respects shutdown signals.

### **Impact**
This would:
- Improve reliability when shutting down applications running Elsa Workflows.
- Ensure workflows reach a **natural stopping point** before termination.
- Provide a **consistent and extensible** mechanism for module developers.

Contributor guide

Open the contributing guide

Research direction

Start by mapping the WorkflowRunner or equivalent execution engine against the application shutdown signal, then review how MassTransit consumers, Quartz.NET, Hangfire, and HTTP workflow-start endpoints accept work. Consider the proposed shutdown token, global notification event, and IShutdownHandler entry points. Done means active workflows reach a commit point, new work is rejected or paused, and extensions can clean up consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.