Skip to content

MatrixHttpClient concurrency issue #1

@Devmios1me

Description

@Devmios1me

I encountered a crash in CommandListenerHostedService due to a race condition in MatrixHttpClient.SendAsync.

fail: LibMatrix.Utilities.Bot.Services.CommandListenerHostedService[0]
      Failed to sync!
      System.IndexOutOfRangeException: Index was outside the bounds of the array.
         at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
         at LibMatrix.Extensions.MatrixHttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
         at LibMatrix.Extensions.MatrixHttpClient.GetFromJsonAsync[T](String requestUri, JsonSerializerOptions options, CancellationToken cancellationToken)
         at LibMatrix.Helpers.SyncHelper.SyncAsyncInternal(Nullable`1 cancellationToken, Boolean noDelay)

Could you change
private Dictionary<HttpRequestMessage, int> _retries = []; to ConcurrentDictionary or add locking logic to prevent race conditions?

Thank you for your great job!

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