Skip to content

Check promise states in conversation timeout callback | timeouts & nested conversations #2407

@Bibo-Joshi

Description

@Bibo-Joshi

When using ConversationHandler with async handler callbacks and timeout, the timeout may trigger falsely. This is the case, when the callback returns CH.END, which currently the timeout callback doesn't know.

This can be solved by making CH._trigger_timeout check if the current conversations state as follows:

if isinstance(state, Promise):
    if state.done and state.result() == CH.END:
        return

This will still fail, if the promise is not yet done, when the timeout triggers but

  1. it's a best effort solution
  2. if a promise takes longer to run than the timeout is, then there are probably some other issues in the users code

Also when looking at the code I noticed that we don't handle nested conversations in CH._trigger_timeout, so that's a good opportunity to fix that …

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions