Nhowka / Elmish.Bridge

Create client-server Fable-Elmish apps keeping a single mindset
MIT License
139 stars 17 forks source link

Object reference not set to an instance of an object #46

Closed leolorenzoluis closed 2 years ago

leolorenzoluis commented 2 years ago

I receive the following error when I push a lot of messages in multiple threads. Any guidance what it could mean? It works fine for few background threads and then it dies

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Elmish.RingBuffer`1.Pop()
   at Elmish.ProgramModule.dispatch@140.Invoke(msg msg)
   at Elmish.Cmd.OfAsyncWith.bind@131-16.Invoke(msg _arg1)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 465
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
--- End of stack trace from previous location ---
   at Microsoft.FSharp.Control.AsyncPrimitives.Start@1078-1.Invoke(ExceptionDispatchInfo edi) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 1078
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
   at <StartupCode$FSharp-Core>.$Async.clo@181-16.Invoke(Object o) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 183
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()
Alkasai commented 2 years ago

Same

Nhowka commented 2 years ago

I'm thinking that the Elmish ring buffer is not friendly when using multiple threads. I'll check the issues with it and probably revert it to using a MailboxProcessor again.

Alkasai commented 2 years ago

Do you know when you are planning to do this? Do you need any help? I'm not familiar with the code-base, but who knows maybe I can help with anything.

Nhowka commented 2 years ago

A minimal repro code for the issue would be excellent. I tried to look at it earlier today, but only the stack trace didn't give me much information to understand the problem's root cause.

Alkasai commented 2 years ago

For sure.

Nhowka commented 2 years ago

I'm uploading version 6.0.3, which uses a MailboxProcessor to control the access to the Elmish dispatcher, hopefully fixing the problem with multi-threading.

Alkasai commented 2 years ago

Thank you! Will give it a try.

Alkasai commented 2 years ago

Seems to be working. Thank you again, for the prompt fix!