Skip to content

Possible bug in permessage_deflate handling: invalid stored block length on async_read #3028

@shinny-zhangyihang

Description

@shinny-zhangyihang

First of all, thank you for maintaining Boost.Beast! It’s an excellent library with great design and documentation, and it has been very helpful for our WebSocket projects.

While using Boost.Beast extensively, we encountered an issue that seems unusual and might be a bug, specifically related to permessage-deflate compression in the WebSocket client.

That said, when using Boost.Beast as a WebSocket client with permessage-deflate enabled, we occasionally encounter errors during async_read. Specifically, the error code returned is:
ec: invalid stored block length

We used the following WebSocket client configuration:

websocket::permessage_deflate pmd;
pmd.client_enable = true;
pmd.server_enable = true; 
pmd.client_no_context_takeover = false; 
pmd.server_no_context_takeover = false;
ws.set_option(pmd);

During communication, async_read sometimes fails with the above error.

We captured the traffic using Wireshark, and the problematic packet can be read and decompressed correctly by Wireshark, which suggests the issue may be in the client-side handling of compressed frames rather than in the network data.

After further investigation, we were able to narrow down the potential cause. We created a minimal example that reliably reproduces the issue. In addition, we submitted a pull request proposing a fix, and testing shows that the proposed changes successfully resolve the problem:

shinnytech#1

We realize that our understanding of the internal workings of Boost.Beast, especially in the permessage-deflate implementation, is limited. We would greatly appreciate it if the maintainers could take a closer look and provide guidance or suggestions for a more robust solution. Your expertise would be invaluable in helping us understand and properly address this issue.

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