← 输入框|github.com|刷新
Skip to content

Encoder Reuse Bug? #212

Closed
Closed

Description

@turnerEP

Hello!
I have an issue with reusing Encoder instances.
For some reason decoding fails in some cases. ("Extra 224 of 233 byte(s)", "Insufficient data")
The bug does not happen when just using the default encode function.
I am able to reproduce the problem with this script: https://gist.github.com/turnerEP/852147711da016ebb22296f75dbf7360
I am kinda confident that this is not expected behavior.

Cheers!

Activity

  1. ProTip commented on Sep 1, 2022

    @ProTip

    Landed on this today as well doing perf testing sending 170k messages at a time between a client and server.

    It's definitely the encoder too. It always errors on the 150k(th) message but it's not that specific message or the one prior.. It seems to get into a bad state based on everything that came before(or at least a subset that I have not identified).

    Here is a hex encoding of the bad data the encoder generated which failed on decode:

    9301ce000249f094a761727469636c65ad41424344454647313439393939a973756273637269626581a77375636365
    
  2. added a commit that references this issue on Sep 2, 2022
    9050c93
  3. added a commit that references this issue on Sep 2, 2022
    da998c6
  4. gfx commented on Sep 2, 2022

    @gfx
    Member

    @turnerEP @ProTip

    Thank you for your report. I can reproduce it with your gist. The behavior was designated because Encoder#encode() returned the shared reference of the internal ArrayBuffer of the encoder. That's why it was faster than a function version of encode().

    However, I've confirmed the behavior was confusing and the results of misuse were hard to debug. So I've changed the behavior at v2.8.0 to return a copy of the internal buffer of the encoder.

    If you'd like to have a faster encoder and know what you are doing, use Encoder#encodeSharedRef(), which returns the shared reference of the encoder. The tests added in #213 might help you to understand the behavior.


    FWIW I can't decode what @ProTip reported, so please file another issue if your problem is not fixed yet.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions