masastack / MASA.Framework

.NET next-generation microservice development framework, which provides cloud native best practices based on Dapr.
https://docs.masastack.com/framework/getting-started/overview
MIT License
695 stars 111 forks source link

.net8环境下,雪花ID在使用Redis的时候发生Stack overflow异常 #686

Open januswx opened 6 months ago

januswx commented 6 months ago

Description

Stack overflow. Repeat 2911 times:

at System.Text.Json.JsonSerializer.WriteCore[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Text.Json.Utf8JsonWriter, System.Canon ByRef, System.Text.Json.Serialization.Metadata.JsonTypeInfo1<System.__Canon>) at System.Text.Json.JsonSerializer.Serialize[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Text.Json.Utf8JsonWriter, System.__Canon, System.Text.Json.JsonSerializerOptions) at System.Text.Json.Serialization.JsonConverter1[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(System.Text.Json.Utf8JsonWriter, System.Canon ByRef, System.Text.Json.JsonSerializerOptions, System.Text.Json.WriteStack ByRef) at System.Text.Json.Serialization.JsonConverter`1[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(System.Text.Json.Utf8JsonWriter, System.Canon ByRef, System.Text.Json.JsonSerializerOptions, System.Text.Json.WriteStack ByRef)

at System.Text.Json.JsonSerializer.WriteCore[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Text.Json.Utf8JsonWriter, System.Canon ByRef, System.Text.Json.Serialization.Metadata.JsonTypeInfo1<System.__Canon>) at System.Text.Json.JsonSerializer.Serialize[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Text.Json.Utf8JsonWriter, System.__Canon, System.Text.Json.JsonSerializerOptions) at System.Text.Json.Serialization.JsonConverter1[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(System.Text.Json.Utf8JsonWriter, System.Canon ByRef, System.Text.Json.JsonSerializerOptions, System.Text.Json.WriteStack ByRef) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson(System.Object, System.Text.Json.WriteStack ByRef, System.Text.Json.Utf8JsonWriter) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(System.Text.Json.Utf8JsonWriter, System.Canon, System.Text.Json.JsonSerializerOptions, System.Text.Json.WriteStack ByRef) at System.Text.Json.Serialization.JsonConverter1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(System.Text.Json.Utf8JsonWriter, System.__Canon ByRef, System.Text.Json.JsonSerializerOptions, System.Text.Json.WriteStack ByRef) at System.Text.Json.Serialization.JsonConverter1[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(System.Text.Json.Utf8JsonWriter, System.Canon ByRef, System.Text.Json.JsonSerializerOptions, System.Text.Json.WriteStack ByRef) at System.Text.Json.JsonSerializer.WriteCore[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Text.Json.Utf8JsonWriter, System.Canon ByRef, System.Text.Json.Serialization.Metadata.JsonTypeInfo1<System.__Canon>) at System.Text.Json.JsonSerializer.WriteString[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef, System.Text.Json.Serialization.Metadata.JsonTypeInfo1) at Masa.Contrib.Caching.Distributed.StackExchangeRedis.RedisCacheClient.Publish(System.String, System.Action`1) at Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.DistributedWorkerProvider.GetWorkerIdAsync() at Masa.Contrib.Data.IdGenerator.Snowflake.Internal.WorkerIdBackgroundServices+d7.MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Masa.Contrib.Data.IdGenerator.Snowflake.Internal.WorkerIdBackgroundServices+d7, Masa.Contrib.Data.IdGenerator.Snowflake, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](d7 ByRef) at Masa.Contrib.Data.IdGenerator.Snowflake.Internal.WorkerIdBackgroundServices.ExecuteAsync(System.Threading.CancellationToken) at Microsoft.Extensions.Hosting.BackgroundService.StartAsync(System.Threading.CancellationToken) at Microsoft.Extensions.Hosting.Internal.Host+d12.MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.Extensions.Hosting.Internal.Host+d12, Microsoft.Extensions.Hosting, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](d12 ByRef) at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(System.Threading.CancellationToken) at Microsoft.AspNetCore.Builder.WebApplication.StartAsync(System.Threading.CancellationToken) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions+d4.MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions+d4, Microsoft.Extensions.Hosting.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](d4 ByRef) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(Microsoft.Extensions.Hosting.IHost, System.Threading.CancellationToken) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(Microsoft.Extensions.Hosting.IHost) at Microsoft.AspNetCore.Builder.WebApplication.Run(System.String) at Program+<

$>d0.MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Canon ByRef) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[System.Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Canon ByRef) at Program.
$(System.String[]) at Program.
(System.String[])

Reproduction Steps

services.AddSnowflake(distributedIdGeneratorOptions =>
{
    distributedIdGeneratorOptions.UseRedis(
        option => option.GetWorkerIdMinInterval = 5000, redisConfigurationOptions);
});

Expected behavior

No response

Actual behavior

No response

Known Workarounds

情况与 issue #560 相同,#560 通过在services.AddMultilevelCache中自定义JsonSerializerOptions,可以解决,但是在雪花ID这里没有自定义JsonSerializerOptions的地方。

.NET version

8.0

MASA Framework version

1.0.0

Other information

No response

duiapro commented 3 months ago

请提供完整项目