Skip to content

Graceful Shutdown ignores Websocket handler task #3003

Open
@SZenglein

Description

@SZenglein

Bug Report

Version

axum 0.7.4

Platform

Linux [...] 6.11.3-200.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Oct 10 22:31:19 UTC 2024 x86_64 GNU/Linux

Crates

axum

Description

I have the following scenario:

  • I need websocket connections which contain shared references (Arc) to the application state
  • Sometimes I need to stop the service and be sure all shared state is dropped
  • I am using graceful shutdown

The concrete reason the state needs to be dropped is that it may contain a file handle that is exclusive and that I want to access after shutting down.

The problem:
The task spawned in ws.on_upgrade is not connected to the graceful shutdown future at all. I can listen to a global CancellationToken and quit the connection myself, but that still does not guarantee me that the connection is closed when the graceful shutdown future completes.
If I don't immediately quit the application after the server quits, the websocket connection happily continues running. Try placing a sleep below the axum::serve.

I would expect websockets to behave the same as SSE, i.e. blocking graceful shutdown until completion (#2673).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions