question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bot silently stops receiving updates when it gets a message that fails to parse

See original GitHub issue

Well, that’s not funny anymore. It happened again, one more time, and it happened countless times before. The bot just got another message with slightly modified JSON markup (games this time) that it failed to parse. And it again just stopped processing all updates, even those that were correct.

Bot was in polling mode.

Failing message
{
  "update_id": 16538441,
  "edited_message": {
    "message_id": 1015764,
    "from": {
      "id": 1599103365,
      "is_bot": false,
      "first_name": "m0unteni [block toxic]",
      "username": "m0unteni"
    },
    "chat": {
      "id": -1000123456,
      "title": "Group title",
      "username": "group_username",
      "type": "supergroup"
    },
    "date": 1637011117,
    "edit_date": 1637011143,
    "game": {
      "title": "Keep it UP",
      "text": "Top Players\n1. m0unteni [block toxic] – 3",
      "text_entities": [
        {
          "offset": 0,
          "length": 11,
          "type": "bold"
        },
        {
          "offset": 40,
          "length": 1,
          "type": "bold"
        }
      ],
      "description": "Time for some football freestyle! Keep it UP!",
      "photo": [
        {
          "file_id": "AgACAgQAAxUAAWGSzsc6ls4XQ4kPR49ns9fbCbp8AAIKrTEbtmhxUSW6OTezqSMYAQADAgADcwADIgQ",
          "file_unique_id": "AQADCq0xG7ZocVF4",
          "file_size": 1360,
          "width": 90,
          "height": 51
        },
        {
          "file_id": "AgACAgQAAxUAAWGSzsc6ls4XQ4kPR49ns9fbCbp8AAIKrTEbtmhxUSW6OTezqSMYAQADAgADbQADIgQ",
          "file_unique_id": "AQADCq0xG7ZocVFy",
          "file_size": 12556,
          "width": 320,
          "height": 180
        },
        {
          "file_id": "AgACAgQAAxUAAWGSzsc6ls4XQ4kPR49ns9fbCbp8AAIKrTEbtmhxUSW6OTezqSMYAQADAgADeAADIgQ",
          "file_unique_id": "AQADCq0xG7ZocVF9",
          "file_size": 26959,
          "width": 640,
          "height": 360
        }
      ],
      "animation": {
        "file_name": "animation.mp4",
        "mime_type": "video/mp4",
        "duration": 5,
        "width": 320,
        "height": 180,
        "thumb": {
          "file_id": "AAMCBAADFQABYZLOx2VPMYUFnXKujlkcc_fU7r0AAtUEAAK2aHFRaML43E0g8oUBAAdzAAMiBA",
          "file_unique_id": "AQAD1QQAArZocVF4",
          "file_size": 1569,
          "width": 90,
          "height": 50
        },
        "file_id": "CgACAgQAAxUAAWGSzsdlTzGFBZ1yro5ZHHP31O69AALVBAACtmhxUWjC-NxNIPKFIgQ",
        "file_unique_id": "AgAD1QQAArZocVE",
        "file_size": 95370
      }
    },
    "reply_markup": {
      "inline_keyboard": [
        [
          {
            "text": "Play Keep it UP!",
            "callback_game": {}
          }
        ]
      ]
    },
    "via_bot": {
      "id": 280713127,
      "is_bot": true,
      "first_name": "Gamee",
      "username": "gamee"
    }
  }
}

Serialization mechanism where one failing message could block all update queue is a huge problem and can lead to silent denial-of-service scenarios.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ex0nscommented, Nov 19, 2021

5.1.0 published with the fix, closing this for now. Feel free to re-open an issue if this is still a problem

1reaction
makkarpovcommented, Nov 18, 2021

Looks good!

Typing can be made clearer by introducing custom sealed trait instead of doing 4-th level of generics, like that:

sealed trait ParsedUpdate
object ParsedUpdate {
  case class Failure(updateId: Long, cause: DecodingFailure) extends ParsedUpdate
  case class Success(update: Update) extends ParsedUpdate
}

Conversion from raw update type to wrapped should be rather straightforward and can be done by wrapping a decoder object.

As for that assert: if assertion failure would result in circe DecodingFailure - I don’t think that there is a need for removal. Anyway update with an unknown event (so that every field is None) is a malformed update from library’s perspective.

If decoder is unable to decode even updateId - I think that whole request should fail because something really bad is happening.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bot stops receiving messages · Issue #183 - GitHub
This kind of error is returned by Telegram system and the parsing problem is because it doesn't contains an actual JSON payload (but...
Read more >
Updating from v12 to v13 - discord.js Guide
To check your Node version, use node -v in your terminal or command prompt, and if it's not high enough, update it! There...
Read more >
Known issues - Microsoft Open Source
The information in this documentation is not guaranteed to work for Bot Framework SDK versions past 4.9.1. Known issues. HTTP 401 Error when...
Read more >
API Reference - discord.py - Read the Docs
This is currently used to refresh the view's state during message update events. If not given then message update events are not propagated...
Read more >
telegram - Bot isn't receiving updates from some chats
Once the bot is added in a group, it remembers that privacy setting. If you change privacy settings via botfather actually it won't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found