Skip to content

PostData.MultiJson broken when direct streaming is disabled #150

@dawust

Description

@dawust

Elastic.Clients.Elasticsearch version: 8.16.1 (works in 8.14.6)

When writing data using PostData.MultiJson, the FinishStream(Async) method is incorrectly duplicating data into the same buffer when disableDirectStreaming is set to true. This happens because BufferIfNeeded modifies writableStream by reference to use a newly created MemoryStream buffer, but FinishStream later uses the same writableStream (now the buffer) for copying, resulting in self-copying and data duplication.

Steps to Reproduce

Use PostData.MultiJson with disableDirectStreaming set to true.
Observe that the data in WrittenBytes is duplicated.

Solution
I think, the issue can be resolved by introducing a local variable stream to hold the current writing stream, ensuring that the original writableStream remains distinct from the buffer. The local stream is used for writing data, while the original writableStream is used correctly in FinishStream.

#149

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