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

.NET 8 raises System.AccessViolationException when Org.Apache.Kafka.Streams.KeyValue<K, V> is retrieved from Org.Apache.Kafka.Streams.State.KeyValueIterator<K, V> #345

Closed
masesdevelopers opened this issue Jan 16, 2024 · 1 comment · Fixed by #359
Assignees
Labels
bug Something isn't working KNet KNet related issue .NET Pull requests that update .net code

Comments

@masesdevelopers
Copy link
Contributor

masesdevelopers commented Jan 16, 2024

Describe the bug
Under .NET 8 environment Org.Apache.Kafka.Streams.State.KeyValueIterator<K, V> many times raises System.AccessViolationException when Org.Apache.Kafka.Streams.KeyValue<K, V> is retrieved

To Reproduce
See masesgroup/KEFCore#194

Expected behavior
Since in .NET 6 and .NET 7 the issue is not raised, the expectation is the same for .NET 8

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Windows 10
  • .NET 8 version 8.0.1
  • Version: latest release 2.3.0

Additional context
See masesgroup/KEFCore#194

@masesdevelopers masesdevelopers added bug Something isn't working KNet KNet related issue .NET Pull requests that update .net code labels Jan 16, 2024
@masesdevelopers masesdevelopers self-assigned this Jan 16, 2024
@masesdevelopers masesdevelopers changed the title .NET 8 raises System.AccessViolationException when KeyValue<K, V> is retrieved from KeyValueIterator<K, V> .NET 8 raises System.AccessViolationException when Org.Apache.Kafka.Streams.KeyValue<K, V> is retrieved from Org.Apache.Kafka.Streams.State.KeyValueIterator<K, V> Jan 16, 2024
@masesdevelopers
Copy link
Contributor Author

Seems that the .NET Garbage Collector retires the Org.Apache.Kafka.Streams.KeyValue<K, V> object, releasing the underlying JVM object; this implies that the pointer stored is no more valid and the access to the data raises the exception. A possible workaround can be to instruct the .NET Garbage Collector to stop its execution around the critical region using GC.TryStartNoGCRegion ending it with GC.EndNoGCRegion:

#if NET8_0
bool startedGCRegion = false;
startedGCRegion = GC.TryStartNoGCRegion(1024, false);
#endif

// critical region

#if NET8_0
if (startedGCRegion && GCSettings.LatencyMode == GCLatencyMode.NoGCRegion) GC.EndNoGCRegion();
#endif

The memory, in the previous example is 1024, can be changed based on the application using the Org.Apache.Kafka.Streams.State.KeyValueIterator<K, V>, the second parameter is set to false to avoid an usefulness full GC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working KNet KNet related issue .NET Pull requests that update .net code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant