Skip to content

IndexOutOfRangeException when using StreamTrimMode.Acknowledged in StreamAddAsync #2940

@ejlalzadeh

Description

@ejlalzadeh

Getting "Index was outside the bounds of the array" exception when publishing to Redis stream using StreamAddAsync with StreamTrimMode.Acknowledged. The same code works fine with StreamTrimMode.KeepReference.

Environment:

  • StackExchange.Redis version: 2.8.58
  • .NET version: .NET 5.0
  • Redis server version: 8.2.0 (running on Docker)

Code that fails:

await database.StreamAddAsync(
    streamName,
    maxLength: maxLength,
    useApproximateMaxLength: true, 
    trimMode: StreamTrimMode.Acknowledged,  // Throws exception
    streamPairs: nameValueEntries);

Code that works:

await database.StreamAddAsync(
    streamName,
    maxLength: maxLength,
    useApproximateMaxLength: true, 
    trimMode: StreamTrimMode.KeepReference,  // Works fine
    streamPairs: nameValueEntries);

Stack Trace:

Index was outside the bounds of the array.
   at StackExchange.Redis.RedisDatabase.GetStreamAddMessage(RedisKey key, RedisValue entryId, Nullable`1 maxLength, Boolean useApproximateMaxLength, NameValueEntry[] streamPairs, Nullable`1 limit, StreamTrimMode mode, CommandFlags flags)
   at StackExchange.Redis.RedisDatabase.StreamAddAsync(RedisKey key, NameValueEntry[] streamPairs, ...)

Expected behavior: StreamTrimMode.Acknowledged should work without throwing array bounds exceptions.

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