Skip to content

AsyncListenWebSocketClient.finish swallows CancelledError and may prevent proper cleanup #570

@filipi87

Description

@filipi87

What is the current behavior?

When calling finish() on AsyncListenWebSocketClient, if an error occurs, the implementation swallows asyncio.CancelledError. This can lead to async tasks not being properly cancelled, leaving background tasks or threads hanging.

Steps to reproduce

  • Run Deepgram inside an asyncio task.
  • From outside, cancel that task while it is in the middle of await finish().
  • Because of the race condition between the cancellation signal and the shutdown sequence, finish() swallows the CancelledError.

Expected behavior

finish() should properly propagate CancelledError or re-raise after logging.

Please tell us about your environment

This issue is happening inside Pipecat, when we are cancelling the Pipeline.
For now we have included a workaround to prevent the Pipeline from freezing due to this.

Other information

Since CancelledError is a control-flow exception in asyncio and should normally propagate, catching it without re-raising breaks task cancellation semantics. This can result in:

  • Potential resource leaks or threads that remain active after shutdown
  • Inconsistent cleanup behavior if cancellation occurs during finish()

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