octokit / octokit.net

A GitHub API client library for .NET
https://octokitnet.readthedocs.io/en/latest/
MIT License
2.65k stars 1.07k forks source link

[BUG]: Duplicate entries for Repository.Release.GetAll(...) #2710

Open sommmen opened 1 year ago

sommmen commented 1 year ago

What happened?

It seems that in production my app occasionally retrieves duplicate rows. I can't seem to reproduce this locally but i see errors in production;

Found duplicate releases, upsert may fail: [....]
var duplicateReleases = releases
    .GroupBy(k => k.ExternalId, (k, rows) => new
    {
        k,
        rows = rows.ToList()
    })
    .Where(c => c.rows.Count > 1)
    .ToList();

if (duplicateReleases.Any())
{
    using var loggerScope = Logger.BeginScope(new Dictionary<string, object>()
    {
        {"@" + nameof(duplicateReleases), duplicateReleases}
    });

    Logger.LogError("Found duplicate releases, upsert may fail: {@dupes}", duplicateReleases.Select(c => c.k).ToList());
}

I'm using my own DTO, ExternalId is simply Release.Id

This seem to happen occasionally and i've never encountered it on my local machine.

private async IAsyncEnumerable<Release> GetReleases(string owner, string name, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
    var jitter = new Random();
    const int maxPageSize = 100;
    var page = 1;
    while (true)
    {
        cancellationToken.ThrowIfCancellationRequested();

        var releases = await _client.Repository.Release.GetAll(owner, name, new ApiOptions
        {
            PageSize = maxPageSize,
            PageCount = 1,
            StartPage = page++,
        });

        if (!releases.Any())
            yield break;

        foreach (var release in releases)
        {
            yield return release;
        }

        await Task.Delay(jitter.Next(0, 500), cancellationToken);
    }
}

The latest instance has 38 duplicates. The repo has 1093 releases.

I've checked that these are actual duplicates, for the same id i get 2 of the same entries, with the same tagName (All other proeprties are the same too);

image

Any clues on why this is or am i doing something dumb?

Versions

<PackageReference Include="Octokit" Version="5.1.0" /> .net7

Relevant log output

No response

Code of Conduct

Cyberboss commented 1 year ago

I've also seen rows missing. Impossible to repro reliably, but maybe try https://github.com/tgstation/tgstation-server

github-actions[bot] commented 3 weeks ago

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

Cyberboss commented 3 weeks ago

Definitely still an issue