C# async export traps when the caller cancels it
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 22/100
Piste de recherche
Start in crates/csharp/src/AsyncSupport.cs, especially AsyncSupport.Callback, and trace how EventCode.Cancel with waitable 0 reaches the pendingTasks[set][e.Waitable] lookup. The issue names the needed pieces: import [task-cancel]/[subtask-cancel], handle cancellation in Callback, track whether task.return ran, and zero handles in ReaderBase.Dispose. Reproduce with the WIT example through cargo run test --languages rust,csharp; done means the C# export no longer traps, cancelled tasks complete as cancelled, handles are dropped once, and a runtime test covers a caller-cancelled waiting export.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
A C# async export cannot handle a call that the caller cancels while the export waits. The runtime support traps on the cancel event, and the generated code never calls task.cancel.
Where
crates/csharp/src/AsyncSupport.cs, AsyncSupport.Callback. The method does not look at the event code. It starts with pendingTasks[set][e.Waitable]. A cancel request arrives as EventCode.Cancel with waitable 0, so the lookup throws KeyNotFoundException: The given key '0' and the component traps.
Also:
- No C# code imports
[task-cancel]or[subtask-cancel]. The generator leaves// TODO: task_cancel.forget();in every async export. WaitableInfoStatekeeps no subtask handle for an async import call, so such a call cannot be cancelled either.
Reproduction
package my:test;
interface i {
pending: async func(x: future);
}
world test {
export i;
}
world runner {
import i;
export run: async func();
}
The C# export:
public static async Task Pending(FutureReader x)
{
await x.Read();
}
A Rust runner creates a future, calls pending(rx), polls the call once (it is pending), drops it, and writes to the future. A cancelled callee has dropped its reader, so the write must fail.
Result: the C# component traps before the drop completes.
Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key '0' was not present in the dictionary.
at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNotFoundException(TKey)
at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey)
at TestWorld.AsyncSupport.Callback(EventWaitable)
at TestWorld.wit.Exports.my.test.IExportsInterop.PendingCallback(Int32, UInt32, UInt32)
Control: the same runner with a Rust export (async fn pending(x: FutureReader<()>) { x.await }) passes, and the write fails as expected.
Run through wit-bindgen's test harness (cargo run test --languages rust,csharp …) with .NET SDK 10.0.403, WASI SDK 34 and wasmtime 51.0.0-dev, on the branch of #1758, which does not change AsyncSupport.cs.
No existing runtime test cancels a waiting C# export, so this path never ran before. The disabled C# future-cancel-read test (#1652) is a different case: there the export cancels its own read, nobody cancels the export.
Related, found by reading (not measured)
- The normal exit path of
Callbackfrees the context but does not drop the waitable set and does not remove thependingTasksentry. A C# export task that waits at least once probably keeps one host waitable set and one dictionary entry. ReaderBase.Disposedrops the handle but does not set it to zero. A secondDisposewould drop the handle twice.
What a fix needs
- Import
[task-cancel](from[export]$root) and[subtask-cancel]. - A cancel path in
CallbackforEventCode.Cancel: cancel each operation in flight (cancel-read/cancel-writefor futures and streams,subtask.cancelfor import calls), complete the .NET tasks as cancelled, drop the reader or writer handles, drop the waitable set, free the context, and calltask.cancelunless the export already returned. - A way for the runtime to know that
task.returnalready ran, so thattask.cancelis never called after it or twice. Disposethat sets the handle to zero.
User code runs inside the callback when its task completes as cancelled, so the cancel path must take a snapshot of the pending waitables first and must check whether the user code joined a new waitable before it drops the set.
- Langage dominant
- Rust
- Étoiles
- 1.5k
- Forks
- 306
- Merge moyen
- 1 j 4 h
- PR mergées (30 j)
- 21
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Aucun guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de bytecodealliance/wit-bindgen
-
gen-rust
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
bytecodealliance/wit-bindgen#1791 ·
Les mainteneurs répondent en général sous 1 jour
-
gen-rust
Difficulté 4/5 3-5 jours Accessibilité débutants 22/100
bytecodealliance/wit-bindgen#1790 ·
Les mainteneurs répondent en général sous 1 jour
-
Document build.rs approachOuvertegen-rust
Difficulté 3/5 Une demi-journée Accessibilité débutants 55/100
bytecodealliance/wit-bindgen#1787 ·
Les mainteneurs répondent en général sous 1 jour
-
Async exports never free the block of indirect parametersPeut-être pris @Aditya1404Sal l’a pris il y a 37 jours. Ouverteasync
Difficulté 4/5 3-5 jours Accessibilité débutants 30/100
bytecodealliance/wit-bindgen#1757 ·
Les mainteneurs répondent en général sous 1 jour
-
gen-rust
Difficulté 4/5 3-5 jours Accessibilité débutants 42/100
bytecodealliance/wit-bindgen#1754 · 7 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de bytecodealliance/wit-bindgen
Issues similaires
-
lane:collections todo:ticket
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 3 jours
-
bugfix
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
storytold/designcraft#3662 ·
Les mainteneurs répondent en général sous 1 jour
-
documentation
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
good first issue tooling
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Nixitov/Riptide-Native#521 ·
Les mainteneurs répondent en général sous 1 jour