Skip to content

Invalid messages crash a channel's message queue, and blocks can't be sent #19

Open

Description

@ryanwinchester

send_message/2 accepts any message and returns :ok, and the channel's Slack.MessageServer only fails when it gets to that message. When it crashes, every message queued behind it for that channel is lost, and repeated crashes can take down Slack.DynamicSupervisor along with every other channel's queue.

Two ways to hit it:

  • A message that isn't a string, map or keyword list, for example send_message("C1", 123), raises Protocol.UndefinedError in Enum.into/2.
  • A message with a list value, for example send_message("C1", %{text: "hi", blocks: [...]}), raises ArgumentError because Slack.API.post/3 sends a form body and URI.encode_query/1 doesn't accept lists. The workaround today is blocks: Jason.encode!(blocks).

This happens on main as well as with on-demand queues (#18).

Possible fixes:

  • Validate the message in send_message/2, so a bad one returns {:error, reason} there instead of crashing the queue.
  • Post chat.postMessage as JSON (Slack accepts JSON bodies for it), or JSON-encode list and map values, so blocks and attachments can be passed as data.
  • Rescue a failed post in the queue, log it, and move on to the next message.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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