-
Notifications
You must be signed in to change notification settings - Fork 16
Description
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.