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

Redline: concurrent calls on one Instance silently return wrong values

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java, wasm
领域
backend, compilers

调研方向

The issue is in the Redline backend's machine state, specifically the argsBuffer, callDepth, TRAP_CODE, and pendingException fields which are shared across threads. Start by examining the machine class and the host-call argument passing mechanism. The goal is to implement a thread-owner check on the outermost call to turn silent corruption into an error, as suggested. Look for the compiled calling convention to understand the context pointer.

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

描述

Calling one native Instance from several threads returns wrong results with no error. The other backends do not do this: bytecode is correct, and the interpreter throws. Redline is the only one that answers quietly and wrongly.

Eight threads, 2000 calls each, on a shared instance of host-import-roundtrip.wat.wasm, whose callTakeI32 must always return -1:

Backend Failed calls Wrong results
Interpreter 16000 / 16000 0
Bytecode 0 / 16000 0
Redline (jffi) 5318 / 16000 783

Every Redline failure is TrapException: call stack exhausted. The 783 wrong results carried no error at all.

Cause

Per-call state lives in the machine, shared by every thread that enters it, rather than per thread.

  • argsBuffer is one buffer per machine, and host-call arguments pass through it, so one thread reads another's argument. takeI32 returns what it was handed, which is where the wrong values come from.
  • callDepth is an unsynchronised int, so outermostCall is missed, STACK_LIMIT is never re-anchored, and the stack guard fires against a stale limit.
  • TRAP_CODE and pendingException are shared too, so one thread can see and clear another's trap.

Instances are not thread-safe in general and this may simply be unsupported usage. It is filed for the failure mode rather than the usage: silent wrong answers instead of an error.

Suggested fix

Cheap, and worth doing on its own: compare-and-set an owner thread on the outermost call and throw if another thread is already inside. One atomic operation per outermost call, and it turns silent corruption into an actionable error, which is what the interpreter already does in effect.

Real: per-thread context and argument buffers, and a per-thread call depth. Bigger, because the context pointer is part of the compiled calling convention.

Note on #201

The watchdog fix does not cause this, but it does make it visible. Before it, the same probe gave 0 to 3 wrong results rather than 783: starting a thread per call serialised callers enough that most trapped before they could race. The data race is older than the watchdog work; what went away is the throttle that was hiding it.

🤖 Generated with Claude Code

主要语言
Java
星标
306
派生
20
平均合并
1 天 19 小时
30 天内合并 PR
35

环境准备

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

从这里开始

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

bytecodealliance/endive 的其他 Issue

查看 bytecodealliance/endive 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

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