Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
leolorenzoluis opened this issue Aug 18, 2022 · 8 comments
Closed

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

leolorenzoluis opened this issue Aug 18, 2022 · 8 comments

Comments

@leolorenzoluis
Copy link

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
Copy link
Contributor

Alkasai commented Aug 23, 2022

Same

@Nhowka
Copy link
Owner

Nhowka commented Aug 23, 2022

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
Copy link
Contributor

Alkasai commented Aug 25, 2022

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
Copy link
Owner

Nhowka commented Aug 25, 2022

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
Copy link
Contributor

Alkasai commented Aug 25, 2022

For sure.

  • I start one client subscribes, which receives tons of messages (10s of messages per second) from the server.
  • The messages from the server are sent using hub.SendClientIf(fun client -> client.id = id)
  • I wait for a few minutes and everything is working fine.
  • Next I start a second client, which also receives messages from server using hub.SendClientIf(fun client -> client.id = id)
  • After a few minutes hub.SendClientIf(fun client -> client.id = id) throws 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 Microsoft.FSharp.Core.OptionModule.Iterate[T](FSharpFunc`2 action, FSharpOption`1 option) in D:\a\_work\1\s\src\fsharp\FSharp.Core\option.fs:line 50
   at Server.broadcastToSubscribers@23-1.Invoke(a arg10)
   at Server.subscriberClientMsgFn(SubscriberId sId, ServerToClientMessage yieldedMsg) in C:\Users\.....\Server.fs:line 30```

@Nhowka Nhowka closed this as completed in 82d5fe3 Aug 27, 2022
@Nhowka
Copy link
Owner

Nhowka commented Aug 27, 2022

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
Copy link
Contributor

Alkasai commented Aug 27, 2022

Thank you! Will give it a try.

@Alkasai
Copy link
Contributor

Alkasai commented Aug 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants