SignalR.Orleans icon indicating copy to clipboard operation
SignalR.Orleans copied to clipboard

AddMemoryStreams in ISiloBuilder.UseSignalR can yield duplicate key

Open hendrikdevloed opened this issue 2 years ago • 1 comments

The two other cases are covered by a try...catch in case the user overrode the default, but should the AddMemoryStreams also be conditional in case a SIGNALR_ORLEANS_STREAM_PROVIDER was already registered?

I registered the same memory stream in my startup code but I got an error later on (during app.Run) about a duplicate key. I can imagine the same would happen when trying to register a persistent stream type.

https://github.com/OrleansContrib/SignalR.Orleans/blob/ad56e34e7c177b5be4ae7d3afee43f324478951f/src/SignalR.Orleans/Hosting/ISiloBuilderExtensions.cs#L36C26-L36C26

To keep using the nuget code, a workaround for my particular case is here https://pastebin.com/BetpuqXM but that's not a fundamental solution.

Should there be an if clause around the AddMemoryStreams to check for the presence of a SIGNALR_ORLEANS_STREAM_PROVIDER before registering the memory stream? Try...catch doesn't seem to be a solution because it doesn't generate an exception immediately, in contrast to the previous calls.

(On a related note, should the two try..catch use some lighter non-exception-based mechanism to check for the presence instead?)

hendrikdevloed avatar Oct 27 '23 09:10 hendrikdevloed

My silo start and fail at this line too, the exception is :

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast object of type 'Orleans.Storage.MemoryGrainStorage' to type 'Orleans.ILifecycleParticipant`1[Orleans.Runtime.ISiloLifecycle]'.
  Source=Orleans.Runtime
...

I register AddAdoNetGrainStorage first and it broken in UseSignalR() line:

 builder.AddMemoryStreams("SIGNALR_ORLEANS_STREAM_PROVIDER"); 

personball avatar Nov 16 '24 09:11 personball