Skip to content

Lazy listeners do not work with Chalice local testing server #490

Description

@Cyb-Nikh

I want to perform operations when a member has joined a channel which takes more than 5 seconds, but I'm getting BrokenPipeError: [Errno 32] Broken pipe.

The minimal step to reproduce the same has been shown below while using the lazy listener it waits for 10 seconds before responding back.

Reproducible in:

from chalice import Chalice, Response
from slack_bolt import App
from slack_bolt.adapter.aws_lambda.chalice_handler import ChaliceSlackRequestHandler

bolt_app = App(process_before_response=True)
app = Chalice(app_name='chalice_app_name')
slack_handler = ChaliceSlackRequestHandler(app=bolt_app, chalice=app)


@bolt_app.event("message")
def handle_message_events(body, logger):
    logger.info(body['event']['text'])


def respond_to_slack_within_3_seconds(ack):
    ack("Accepted!")


def say_it(say):
    time.sleep(10)
    say("Done!")


bolt_app.event("member_joined_channel")(
    ack=respond_to_slack_within_3_seconds, lazy=[say_it]
)


@app.route(
    "/slack/events",
    methods=["POST"],
    content_types=["application/x-www-form-urlencoded", "application/json"],
)
def events() -> Response:
    return slack_handler.handle(app.current_request)

The slack_bolt version

slack-bolt==1.9.1
slack-sdk==3.11.1

Python runtime version

Python 3.6.15

OS info

Ubuntu 20.04.3 LTS

Steps to reproduce:

  1. While handling of any Slack event (e.g. handle_member_joined event)
  2. Use lazy listener and wait for more than 3 seconds before responding back to Slack

Expected result:

Since the event is acknowledging the Slack within 3 seconds irrespective of the lazy listener function time, it should have processed the same.

Actual result:

s1
s2

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Activity

  1. seratch commented on Oct 8, 2021

    @seratch
    Contributor

    Hi @Cyb-Nikh, thanks for writing in!

    It seems that you're using Chalice's local testing server. Can I ask you to make sure if the same situation arises without Chalice handler? To verify this, you can use App#start(), Flask adapter or any other adapters. If the issue is specific to Chalice use cases, we can narrow down the issue and may be able to resolve it more quickly.

  2. Cyb-Nikh commented on Oct 8, 2021

    @Cyb-Nikh
    Author

    Hi @seratch, thanks for the response.
    Yes, I'm using Chalice local testing server. I tried using bolt app#start(), it worked perfectly fine. It seems the issue is specific to chalice.

  3. changed the title [-]BrokenPipeError while responding back to a slack event in more than 3 seconds[/-] [+]Lazy listeners do not work with Chalice local testing server[/+] on Oct 10, 2021
  4. seratch commented on Oct 10, 2021

    @seratch
    Contributor

    @Cyb-Nikh Thanks for sharing the result. Unfortunately, we don't have the bandwidth to resolve this issue in the short term. If you figure out how to fix this issue, your pull requests are always welcome!

    As an immediate workaround, I would recommend using Flask dev server for your local development while still using Chalice for production deployments. For instance, your project structure can be:

    • bolt_app.py (configure App instance)
    • local.py (import the app from bolt_app.py and run the app with the default web server or Flask etc.)
    • prod.py (import the app from bolt_app.py and create Chalice handler)

    With this way, you use only bolt_app.py and prod.py for production deployments.

    I hope this was helpful.

  5. added
    bugSomething isn't working
    and removed
    questionFurther information is requested
    on Oct 10, 2021
  6. Cyb-Nikh commented on Oct 10, 2021

    @Cyb-Nikh
    Author

    Thanks for the suggestion @seratch. This can be used as a temporary solution, though I would definitely try to dig further into the possible approach.

  7. added this to the 1.x milestone on Oct 17, 2021
  8. added
    enhancementNew feature or request
    and removed
    bugSomething isn't working
    on Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions