Multiple C# Threads calling WASM Module
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- csharp, wasm
- Ambito
- backend, testing-qa
Direzione di ricerca
Inizia riproducendo lo scenario di unit test C# con due thread, quindi confrontalo con un solo thread e con il caso del lock C#. Traccia l'invocazione WASM condivisa, l'allocazione delle stringhe, la lettura della memoria e le chiamate a _Free mostrate in TryVerify. Questo dovrebbe stabilire il comportamento supportato per le chiamate concorrenti e fornire una risoluzione verificata o una limitazione esplicita.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I have tried to run a WASM module from a C# unit test where there are 2 threads calling the module in a loop. This dies with one of the threads ending in with the following exception
wasm trap: call stack exhausted
Here is logged output from the Test where
- [n] is the thread number
- Count is the iterations for that thread
- Error Count is whether the result was in error (as I was checking for race conditions)
- Exception is the C# exception that was caught from the WASM method Invoke
Debug Trace:
[0] Count: 0 ErrorCount: 0 Exception: error while executing at wasm backtrace:
0: <unknown>!<wasm function 37>
1: 0xb25 - <unknown>!<wasm function 14>
2: 0x47d8 - <unknown>!<wasm function 37>
Caused by:
wasm trap: call stack exhausted
[1] Count: 89498 ErrorCount: 0 Exception:
It is like the WASM module method is being called OK by one thread while the other thread is looks to be calling the method but never leaving it and the stack eventually blew up??
If I run this as 1 thread OR put a C# Lock {} block around the WASM method call, then it all runs fine, and I have called the method for over 5,000,000 iterations without an issue.
The WASM module was written in C and and generated using Emscripten. The method takes in two string (pointers) and a an Int64 and returns a string (pointer).
The memory is being Free'ed.
C method
char* TryVerify(char* token, char* originHeader, uint64_t serverUtcUnixNowMilliseconds)
C# call
object lockObject = new object();
public bool TryVerify(string token, string originHeader, out TokenData tokenData)
{
//lock (lockObject)
//{
var serverUtcUnixNowMilliseconds = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
int inPtrToken = WriteStringToUTF8(token);
int inPtrOriginHeader = WriteStringToUTF8(originHeader);
int outPtr = _TryVerify.Invoke(inPtrToken, inPtrOriginHeader, serverUtcUnixNowMilliseconds);
var json = Memory.ReadNullTerminatedString(outPtr);
_Free(outPtr);
tokenData = System.Text.Json.JsonSerializer.Deserialize<TokenData>(json, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }) ?? throw new Exception("Failed to deserialize token data from wasm");
if (tokenData == null)
{
tokenData = new TokenData();
}
return tokenData.IsOk;
// }
}
- Lingua principale
- C#
- Stelle
- 517
- Fork
- 69
- Merge medio
- 6h 1m
- PR unite (30g)
- 5
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bytecodealliance/wasmtime-dotnet
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
bytecodealliance/wasmtime-dotnet#374 · 2 commenti ·
-
wasip3 supportAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 32/100
bytecodealliance/wasmtime-dotnet#350 · 9 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
-
WasmGCAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
bytecodealliance/wasmtime-dotnet#342 · 8 commenti ·
Tutte le issue di bytecodealliance/wasmtime-dotnet
Issue simili
-
bug next version
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Rem0o/FanControl.Releases#4220 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nkdAgility/azure-devops-migration-tools#3217 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
skoruba/Duende.IdentityServer.Admin#335 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
question
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100