Window is not defined when webworkerservice used by another thread

Aperta
#3 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
49/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, wasm
Ambito
backend, web-dev

Direzione di ricerca

Start with the browser service registration and initialization flow shown in the issue, especially the calls to AddWebWorkerService and StartBackgroundServices, then trace how WebWorkerService accesses the global scope when requested from another thread. Reproduce the failure through the Avalonia UI thread and check whether OPFS calls work there. Done means the service can be accessed from that thread without “Window is not defined” and OPFS calls function.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Attempting to get the web worker service throws with "Window is not defined"
I can fix two of the errors by replacing webWorkerService.GlobalScope == GlobalScope.Window ? 2 : 0 with 0
however, this does not fix functionality, and any calls to OPFS will still throw.

This code gets run by the Avalonia UI thread calling OnFrameworkInitializationCompleted (because my initialization requires async for many things)
Due to this, getting the WebWorkerService and attempting to use it will throw that error in the JS console it seems.

If I move the worker init code outside of the pipeline, I can use it however I like, but the second it is accessed via another thread (such as the Avalonia UI thread), it will throw.

(flow:)

  • Main
  • AppBuilder
  • UniScanApp.Initialize() (called by Avalonia)
  • OnFrameworkInitializationCompleted (called by Avalonia)
  • _ = InitializationPipeline.RunAsync(this); (runs a ton of tasks to initialize everything in a specific order)
  • The following code:

(ALSO VIEWABLE HERE: https://github.com/UniScanProject/UniScan/tree/main/src/Client/UniScan.Client.App.Platform.Browser/Program.cs)

                IServiceCollection browserServices = new ServiceCollection();
                
                browserServices.AddSpawnJSRuntime(out SpawnJSRuntime runtime);
                browserServices.AddWebWorkerService(webWorkerService =>
                {
                    webWorkerService.TaskPool.MaxPoolSize = -1;
                    webWorkerService.TaskPool.PoolSize = webWorkerService.GlobalScope == GlobalScope.Window ? 2 : 0;
                });

                browserServices.AddSingleton<BrowserDirectoryManager>();
                browserServices.AddSingleton<BrowserFileManager>();
                
                browserServices.AddSingleton<IOPFSWorkerService, OPFSWorkerService>();
                IServiceProvider browserServiceProvider = browserServices.BuildServiceProvider();
                await browserServiceProvider.StartBackgroundServices();
                
                ctx.StandardPaths = new BrowserPaths();
                ctx.SerilogInitializer = new BrowserPlatformSerilogInitializer(UniScan.Core.Constants.ConsoleOutputTemplate);
                ctx.FileManager = browserServiceProvider.GetRequiredService<BrowserFileManager>();
                ctx.DirectoryManager = browserServiceProvider.GetRequiredService<BrowserDirectoryManager>();
                
                ctx.ServiceCollection.AddSingleton(runtime);
                ctx.ServiceCollection.AddSingleton<WebWorkerService>(_ => browserServiceProvider.GetRequiredService<WebWorkerService>());
                
                ctx.ServiceCollection.AddSingleton<IPlatformStandardPaths>(_ => ctx.StandardPaths);
                ctx.ServiceCollection.AddSingleton<IPlatformSerilogInitializer>(_ => ctx.SerilogInitializer);
                ctx.ServiceCollection.AddSingleton<IPlatformDirectoryManager>(_ => ctx.DirectoryManager);
                ctx.ServiceCollection.AddSingleton<IPlatformFileManager>(_ => ctx.FileManager);
                ctx.ServiceCollection.AddSingleton<IOPFSWorkerService>(_ => browserServiceProvider.GetRequiredService<IOPFSWorkerService>());
Lingua principale
JavaScript
Stelle
3
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di LostBeard/SpawnDev.SpawnJS.WebWorkers

Tutte le issue di LostBeard/SpawnDev.SpawnJS.WebWorkers

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.