Repository: celery/celery

Issue:
Celery exit with non-zero code after Warm Shutdown in Celery 5.3.x
### Discussed in https://github.com/celery/celery/discussions/8539

<div type='discussions-op-text'>

<sup>Originally posted by **cinesia** September 27, 2023</sup>
We upgraded recently **celery** from **5.2.7** to **5.3.4** and something changed in the default behaviour of a celery worker when it receives a warm shutdown.

Before the upgrade, the worker exited with zero code and now the worker exit with non-zero code (1). 

The code it's the same and nothing changed except the package upgrade. 

I succeed in reproducing the error in a clean environment where only celery is installed.

To reproduce the behaviour: 

- Create a simple Celery worker 

tasks.py
```python
from celery import Celery

app = Celery('tasks')

@app.task
def add(x, y):
    return x + y
```
Dockerfile
```Dockerfile
# Use an official Python runtime as the base image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the dependencies file to the working directory (it has just a line with celery==...)
COPY requirements.txt . 

# Install the dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application's code to the working directory
COPY . .

# Define the command to run your Celery worker
CMD ["celery", "--app=tasks", "worker", "--loglevel=info"]
```

docker-compose
```yaml
version: '3.7'
services:
  # Deploy the broker.
  rabbitmq_server:
    image: rabbitmq:3-management
    ports:
      # Expose the port for the worker to add/get tasks
      - 5672:5672
      # OPTIONAL: Expose the GUI port
      - 15672:15672

  # Deploy the worker
  worker:
    # Build using the worker Dockerfile
    build:
      context: .
      dockerfile: Dockerfile

    # Need to access the database
    # OPTIONAL: If your worker needs to access your db that is deployed locally, then make the network mode as host.
    network_mode: host

    # Pass the rabbitmq_uri as an environment variable in order to connect to our service
    environment:
      # NOTE: Below we are using 127.0.0.1 because this container will run on the host network, thus it will have access to the host network.
      - CELERY_BROKER_URL=amqp://guest@127.0.0.1:5672//
```

- Open a python console inside the celery container and send a shutdown 

```python
import celery

app = celery.Celery("tasks")
app.control.shutdown()
```

If celery == 5.2.7 the container exit with code 0, if celery == 5.3.4 the container exit with code 1.
</div>


Discussion:
If you can propose a fix, it would be great. we can discuss more on the PR.
what is the content of requirements.txt? @cinesia 
> what is the content of requirements.txt? @cinesia 

Just the version of celery I want to install.

Resolving patch:
diff --git a/celery/worker/control.py b/celery/worker/control.py
--- a/celery/worker/control.py
+++ b/celery/worker/control.py
@@ -580,7 +580,7 @@ def autoscale(state, max=None, min=None):
 def shutdown(state, msg='Got shutdown from remote', **kwargs):
     """Shutdown worker(s)."""
     logger.warning(msg)
-    raise WorkerShutdown(msg)
+    raise WorkerShutdown(0)
 
 
 # -- Queues


Test patch: