heroiclabs / nakama-unity

Unity client for Nakama server.
https://heroiclabs.com/docs/unity-client-guide
Other
407 stars 75 forks source link

Illegal Byte Sequence during auth when path has chinese characters in it (mono issue) #146

Closed Donnotron666 closed 1 year ago

Donnotron666 commented 1 year ago

I believe I've found an issue in nakama's auth that's caused by a deeper mono issue.

An initial googling of the error shows that the mono team is regrettably aware of it and has some suggested workarounds. https://github.com/mono/mono/issues/7117

Excerpt from a client log from a user in china, automatically uploaded to our jira....

Error on client auth:System.ArgumentException: Illegal byte sequence encounted in the input. Parameter name: string at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_string_from_byvalstr(intptr,int) at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal.PtrToStructure(intptr,System.Type) at System.Runtime.InteropServices.Marshal.PtrToStructure[T] (System.IntPtr ptr) [0x00000] in <9aad1b3a47484d63ba2b3985692d80e9>:0 at System.Net.NetworkInformation.Win32NetworkInterface.get_FixedInfo () [0x00024] in <a971fed4bf844502b6501dbde9cced46>:0 at System.Net.NetworkInformation.Win32IPGlobalProperties.get_DomainName () [0x00000] in <a971fed4bf844502b6501dbde9cced46>:0 at System.Net.CookieContainer..ctor () [0x0003f] in <a971fed4bf844502b6501dbde9cced46>:0 at System.Net.Http.MonoWebRequestHandler.get_CookieContainer () [0x0000a] in <1461f1930feb4705bca8b5d7908e9fa7>:0 at System.Net.Http.MonoWebRequestHandler.CreateWebRequest (System.Net.Http.HttpRequestMessage request) [0x000f5] in <1461f1930feb4705bca8b5d7908e9fa7>:0 at System.Net.Http.MonoWebRequestHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000cf] in <1461f1930feb4705bca8b5d7908e9fa7>:0 at System.Net.Http.HttpClient.SendAsyncWorker (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) [0x000e8] in <1461f1930feb4705bca8b5d7908e9fa7>:0 at Nakama.HttpRequestAdapter.SendAsync (System.String method, System.Uri uri, System.Collections.Generic.IDictionary2[TKey,TValue] headers, System.Byte[] body, System.Int32 timeout, System.Nullable1[T] userCancelToken) [0x001a2] in <c17a258af24e4d289a30070aa95dc0df>:0 at Nakama.ApiClient.AuthenticateCustomAsync (System.String basicAuthUsername, System.String basicAuthPassword, Nakama.ApiAccountCustom body, System.Nullable1[T] create, System.String username, System.Nullable1[T] cancellationToken) [0x0018d] in <c17a258af24e4d289a30070aa95dc0df>:0 at Nakama.RetryInvoker.InvokeWithRetry[T] (System.Func1[TResult] request, Nakama.RetryHistory history) [0x00198] in :0 at Nakama.Client.AuthenticateCustomAsync (System.String id, System.String username, System.Boolean create, System.Collections.Generic.Dictionary2[TKey,TValue] vars, Nakama.RetryConfiguration retryConfiguration, System.Threading.CancellationToken canceller) [0x000e7] in <c17a258af24e4d289a30070aa95dc0df>:0 at NakamaClient.AwaitWithTimeout[T] (System.Threading.Tasks.Task1[TResult] task, System.String timeoutLogMessage) [0x00141] in <802e6d8b848f4d2bbf1ed8191ede74fb>:0 at NakamaClient.GetOrCreateSessionId () [0x00363] in <802e6d8b848f4d2bbf1ed8191ede74fb>:0 at NakamaClient.Auth (System.String host, System.Int32 port, PlatformId id) [0x00112] in <802e6d8b848f4d2bbf1ed8191ede74fb>:0 at NetworkInit.NakamaLogin () [0x0010b] in <802e6d8b848f4d2bbf1ed8191ede74fb>:0 `

log (1).txt

lugehorsam commented 1 year ago

Hey @Donnotron666 thanks for filing this. Since it's Mono specific and the workaround they suggest seems to involve actually forking the Mono runtime and providing a new character implementation, I think this is out of scope for what we could do in this SDK.

Another approach could be for you to use the UnityWebRequestAdapter instead since this code path is specific to the HttpWebRequestAdapter.