Skip to content

System.InvalidOperationException: The accumulator does not yet have enough entropy to generate data. #9

@RSkhirtladze

Description

@RSkhirtladze

I encountered an issue when calling the GetBytes method in the Fortuna.PRNGFortunaProvider class. The following error is thrown when I invoke the method consecutively from multiple threads:

System.InvalidOperationException: The accumulator does not yet have enough entropy to generate data.
at Fortuna.Accumulator.FortunaAccumulator.GetRandomDataFromPools()
at Fortuna.PRNGFortunaProvider.GetBytes(Byte[] data)

Steps to Reproduce:

  • Create a multi-threaded application with, for example, 10 threads.
  • Create _random = PRNGFortunaProviderFactory.Create(token);
  • In each thread, call the _random.GetBytes method 10,000 times consecutively.
  • Run the program.
  • Observe the System.InvalidOperationException.

Observed Behavior:

The error occurs consistently when GetBytes is called from multiple threads simultaneously.
When the method is invoked consecutively in a single-threaded context, it works without any issue.

The GetBytes method should either be thread-safe or explicitly document that it is not thread-safe.
Is it supposed to be thread-safe?
Why does the error occur specifically when calling the method from multiple threads, but not in single-threaded scenarios?
What changes or precautions should be taken to safely use GetBytes in a multi-threaded environment?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions