DarkRiftNetworking / consul-server-registry-connector

DarkRift ServerRegistryConnector plugin for Consul
MIT License
2 stars 3 forks source link

Errors in Unity-hosted Server #1

Open jvisenti opened 3 years ago

jvisenti commented 3 years ago

I'm attempting to set up clustering for a DarkRift server hosted within a Unity application. This is the only officially supported server registry connector, so I figured I'd look into Consul and give it a shot. Unfortunately it looks like Consul is incompatible with Unity (or more specifically with Mono) due to unimplemented TLS methods:

NotImplementedException: The method or operation is not implemented.
System.Net.Http.HttpClientHandler.set_ServerCertificateCustomValidationCallback (System.Func`5[T1,T2,T3,T4,TResult] value) (at <efff4cb93af94c0c950db61b78368b54>:0)
Consul.ConsulClient.ApplyConfig (Consul.ConsulClientConfiguration config, System.Net.Http.HttpClientHandler handler, System.Net.Http.HttpClient client) (at <dc81860618fc418e92a55d57cf1dfa2d>:0)
Consul.ConsulClient..ctor (System.Action`1[T] configOverride, System.Action`1[T] clientOverride, System.Action`1[T] handlerOverride) (at <dc81860618fc418e92a55d57cf1dfa2d>:0)
Consul.ConsulClient..ctor (System.Action`1[T] configOverride) (at <dc81860618fc418e92a55d57cf1dfa2d>:0)
DarkRift.Server.Plugins.ServerRegistryConnectors.Consul.ConsulServerRegistryConnector..ctor (DarkRift.Server.ServerRegistryConnectorLoadData pluginLoadData) (at DarkRift/consul-server-registry-connector/src/ConsulServerRegistryConnector.cs:49)
System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) (at <9577ac7a62ef43179789031239ba8798>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Reflection.MonoCMethod.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <9577ac7a62ef43179789031239ba8798>:0)
System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Activator.CreateInstance (System.Type type, System.Object[] args) (at <9577ac7a62ef43179789031239ba8798>:0)
DarkRift.Server.PluginFactory.Create[T] (System.Type type, DarkRift.Server.PluginBaseLoadData loadData, DarkRift.Server.PluginLoadData backupLoadData) (at <f0c958ddefe74f5ebdb3653bac4c8e59>:0)
DarkRift.Server.PluginFactory.Create[T] (System.String type, DarkRift.Server.PluginBaseLoadData loadData, DarkRift.Server.PluginLoadData backupLoadData) (at <f0c958ddefe74f5ebdb3653bac4c8e59>:0)
DarkRift.Server.ServerRegistryConnectorManager.LoadPlugins (DarkRift.Server.ServerSpawnData+ServerRegistrySettings settings) (at <f0c958ddefe74f5ebdb3653bac4c8e59>:0)
DarkRift.Server.DarkRiftServer..ctor (DarkRift.Server.ServerSpawnData spawnData, DarkRift.Server.ClusterSpawnData clusterSpawnData) (at <f0c958ddefe74f5ebdb3653bac4c8e59>:0)
DarkRift.Server.Unity.XmlUnityServer.Create (System.Collections.Specialized.NameValueCollection variables) (at Assets/DarkRift/Plugins/Server/XmlUnityServer.cs:95)
DarkRift.Server.Unity.XmlUnityServer.Create () (at Assets/DarkRift/Plugins/Server/XmlUnityServer.cs:55)
DarkRift.Server.Unity.XmlUnityServer.OnEnable () (at Assets/DarkRift/Plugins/Server/XmlUnityServer.cs:40)

If this connector isn't compatible with Unity, it would be helpful to add a note in the README and/or in the DarkRift clustering documentation.

JamJar00 commented 3 years ago

Hey, sorry for the late reply here!

What version of Unity are you running? Can you try running this with IL2CPP?

The Mono Unity ships with is absolutely awful and has broken and half implemented all around Sockets/TLS so I'm not all that surprised to be honest. I thought I'd tested with Unity based servers but I might be imagining it.

The library this uses says it should support Mono so it's looking like it's probably a Unity Mono issue:

Both .NET 4.5+ and .NET Core 1.0+ are fully supported. Mono is supported on a best-effort basis. It should compile and run happily on Mono but this is not as heavily tested as Microsoft .NET stacks. If you have any issues using the Nuget package or compiling this code with .NET, .NET Core, or Mono, please file a Github issue with details of the problem.

jvisenti commented 3 years ago

Unity 2020.2.1f1, API compatibility level .NET 4.x. I'm not sure whether an IL2CPP build would work, but the editor always uses Mono for play mode. I wouldn't be surprised if the problem were specific to Unity Mono 😞

JamJar00 commented 3 years ago

Ugh. I'll try and get a work around sussed out at some point, it might be possible to disable TLS (not great, but not terrible if you're in a VPC etc.) or masybe even submit a PR to the library to fix their Unity Mono compatibility.

Sorry about this!

jvisenti commented 3 years ago

Thanks for the response! I'll check back if anything changes. In the meantime I'll work on a server registry connector that doesn't use Consul.