Skip to content

[Buffer] Buffer.from( ArrayBuffer ) showing stale data on subsequent executions #36327

@croraf

Description

@croraf

What steps will reproduce the bug?

I'm getting the data from the stream as a Buffer 24 bytes long, which contains different data each time called. In the callback I'm trying to split the buffer into two, and log the two new buffers:

    // data is an instance of Buffer, 24 bytes long, and changing each time called (which is dozens of times per second)
    console.log('data1:', data);
    const timestamp = Buffer.from(data.buffer, 0, 16);
    const eventType = Buffer.from(data.buffer, 16, 24);
    console.log('data2:', timestamp, eventType);  // <- showing stale data

What is going on?

Even though my first console.log shows the correct data, the second console.log is showing the stale data for the next events (calls), and only after 12 seconds it updates, and then the next 12 seconds it shows the stale data again, and so on.

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior?

The second console.log should show the same underlying data as the first console.log

What do you see instead?

I see the stale data

data1:  <Buffer 4c 0f c5 5f 00 00 00 00 96 12 00 00 00 00 00 00 02 00 00 00 ff ff ff ff>
data2: <Buffer 4c 0f c5 5f 00 00 00 00 96 12 00 00 00 00 00 00> <Buffer  02 00 00 00 ff ff ff ff> 

data1:  <Buffer 4d 0f c5 5f 00 00 00 00 96 12 00 00 00 00 00 00 02 00 00 00 ff ff ff ff>
data2: <Buffer 4c 0f c5 5f 00 00 00 00 96 12 00 00 00 00 00 00> <Buffer  02 00 00 00 ff ff ff ff> 

Note that in the second pair of outputs data1 changed the first byte, but data2 remained stale.

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.questionIssues that look for answers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions