Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PriorityQueue<TElement, TPriority> edge case Count out of sync #77212

Closed
Tracked by #77391
theodorzoulias opened this issue Oct 19, 2022 · 1 comment · Fixed by #77229
Closed
Tracked by #77391

PriorityQueue<TElement, TPriority> edge case Count out of sync #77212

theodorzoulias opened this issue Oct 19, 2022 · 1 comment · Fixed by #77229

Comments

@theodorzoulias
Copy link
Contributor

theodorzoulias commented Oct 19, 2022

Description

I found an edge case in the PriorityQueue<TElement, TPriority> collection, where enqueuing an element
might fail, but nonetheless the Count increases.

Reproduction Steps

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        PriorityQueue<int, int> queue = new(new (int, int)[300_000_000]);
        Console.WriteLine($"Before Enqueue, Count: {queue.Count:#,0}");
        try
        {
            queue.Enqueue(1, 1);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        Console.WriteLine($"After Enqueue, Count: {queue.Count:#,0}");
    }
}

In my PC I get this output, after around 30 seconds of execution time:

Before Enqueue, Count: 300,000,000
Exception of type 'System.OutOfMemoryException' was thrown.
After Enqueue, Count: 300,000,001

Expected behavior

After failing to Enqueue, the Count should preserve its previous value (300,000,000).

Actual behavior

The Count increases to 300,000,001.

Regression?

No response

Known Workarounds

No response

Configuration

  • .NET 6.0
  • Console application
  • 64-bit operating system, x64-based processor

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 19, 2022
@ghost
Copy link

ghost commented Oct 19, 2022

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I found an edge case in the PriorityQueue<TElement, TPriority> collection, where enqueuing an element
might fail, but the nonetheless the Count increases.

Reproduction Steps

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        PriorityQueue<int, int> queue = new(new (int, int)[300_000_000]);
        Console.WriteLine($"Before Enqueue, Count: {queue.Count:#,0}");
        try
        {
            queue.Enqueue(1, 1);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        Console.WriteLine($"After Enqueue, Count: {queue.Count:#,0}");
    }
}

In my PC I get this output, after around 30 seconds of execution time:

Before Enqueue, Count: 300,000,000
Exception of type 'System.OutOfMemoryException' was thrown.
After Enqueue, Count: 300,000,001

Expected behavior

After failing to Enqueue, the Count should preserve its previous value (300,000,000).

Actual behavior

The Count increases to 300,000,001.

Regression?

No response

Known Workarounds

No response

Configuration

  • .NET 6.0
  • Console application
  • 64-bit operating system, x64-based processor

Other information

No response

Author: theodorzoulias
Assignees: -
Labels:

area-System.Collections, untriaged

Milestone: -

eiriktsarpalis added a commit to eiriktsarpalis/runtime that referenced this issue Oct 19, 2022
@eiriktsarpalis eiriktsarpalis added bug and removed untriaged New issue has not been triaged by the area owner labels Oct 19, 2022
@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone Oct 19, 2022
eiriktsarpalis added a commit that referenced this issue Oct 24, 2022
* Fix #77212.

* Remove unneeded using statement.
@ghost ghost locked as resolved and limited conversation to collaborators Nov 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants