Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

ElasticSerializer async members run synchronous stream I/O and ignore the cancellation token

未关闭
#580 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 7 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
csharp
领域
backend

调研方向

Start with src/Experimental/src/Eventuous.ElasticSearch/Store/ElasticSerializer.cs and inspect all four async members and the PersistedEvent path. Add round-trip tests under src/Experimental/test/, including a PersistedEvent whose Message is remapped through ITypeMapper; use them to guide the async I/O and cancellation changes. Done means stream I/O is asynchronous, cancellation is honored, and the new tests pass.

由索引模型根据 Issue 内容生成。

描述

enhancement perfornamce

src/Experimental/src/Eventuous.ElasticSearch/Store/ElasticSerializer.cs

All four async members of ElasticSerializer delegate straight to their synchronous counterparts and hand back an already-completed task:

public Task<object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default)
    => Task.FromResult(Deserialize(type, stream));

public Task<T> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default)
    => Task.FromResult(Deserialize<T>(stream));

public Task SerializeAsync<T>(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.None, CancellationToken cancellationToken = default) {
    Serialize(data, stream, formatting);

    return Task.CompletedTask;
}

Two consequences:

  1. The stream I/O blocks the calling thread. Deserialize reads the response stream synchronously and Serialize writes through a Utf8JsonWriter synchronously. A caller that awaits DeserializeAsync still pays a blocking read, so the async path buys nothing and can starve the thread pool under load.
  2. cancellationToken is accepted and silently discarded on all four members. Callers reasonably expect a long read to be cancellable; it isn't.
Suggested fix
  • JsonSerializer.DeserializeAsync(stream, type, _options, cancellationToken) for the deserialize path.
  • JsonSerializer.SerializeAsync(stream, data, _options, cancellationToken) for the serialize path — or keep Utf8JsonWriter and switch to FlushAsync + DisposeAsync.
  • Route the non-PersistedEvent branch of SerializeAsync through builtIn.SerializeAsync rather than builtIn.Serialize.

The synchronous members must stay synchronous — IElasticsearchSerializer declares them that way, so they can't be changed. This issue is only about the async ones.

Blocker

ElasticSerializer has no test coverage — src/Experimental/test/ contains only the Spyglass projects. Round-trip tests should land first (or alongside), covering at minimum a PersistedEvent whose Message is remapped through ITypeMapper, since that nested re-deserialization is the part most likely to break in a rewrite.

Context

Surfaced by the Qodo review bot on #578, which flagged the synchronous I/O on lines that are sync by interface contract and were equally synchronous before that PR. Declined there as out of scope for a disposal fix; the real problem is the async delegation above, which predates it.

Low priority — the package is under src/Experimental/.

主要语言
C#
星标
512
派生
99
平均合并
5 天 6 小时
30 天内合并 PR
5

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Eventuous/eventuous 的其他 Issue

查看 Eventuous/eventuous 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。