supabase-community / postgrest-csharp

A C# Client library for Postgrest
https://supabase-community.github.io/postgrest-csharp/api/Postgrest.html
MIT License
117 stars 23 forks source link

Random issues when sending data to API #63

Closed Shenrak closed 1 year ago

Shenrak commented 1 year ago

Bug report

Describe the bug

In a random manner, POST calls seems to fall in error :

With :

await SupabaseManager.app.From<SchemaProgression>().Upsert(_progression);

I get : image

Full stacktrace :

NullReferenceException: Object reference not set to an instance of an object
Postgrest.RequestException..ctor (System.Net.Http.HttpResponseMessage response, Postgrest.Responses.ErrorResponse error) (at Assets/Plugins/Supabase/Postgrest/Helpers.cs:172)
Postgrest.Helpers.MakeRequest (Postgrest.ClientOptions clientOptions, System.Net.Http.HttpMethod method, System.String url, Newtonsoft.Json.JsonSerializerSettings serializerSettings, System.Object data, System.Collections.Generic.Dictionary`2[TKey,TValue] headers, System.Threading.CancellationToken cancellationToken) (at Assets/Plugins/Supabase/Postgrest/Helpers.cs:118)
Postgrest.Helpers.MakeRequest[T] (Postgrest.ClientOptions clientOptions, System.Net.Http.HttpMethod method, System.String url, Newtonsoft.Json.JsonSerializerSettings serializerSettings, System.Object data, System.Collections.Generic.Dictionary`2[TKey,TValue] headers, System.Func`1[TResult] getHeaders, System.Threading.CancellationToken cancellationToken) (at Assets/Plugins/Supabase/Postgrest/Helpers.cs:46)
NodeProgression.DefineSaveLogicAsync () (at Assets/Scripts/Supabase/Schemas/SchemaProgression.cs:99)
UnityEngine.Debug:LogException(Exception)
SupabaseNode`1:HandleErrors(Task) (at Assets/Scripts/Supabase/Schemas/Schema.cs:85)
Firebase.Extensions.<>c__DisplayClass2_1`1:<ContinueWithOnMainThread>b__1() (at /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/task_extension/TaskExtension.cs:87)
Firebase.<>c__DisplayClass5_0`1:<RunAsync>b__0() (at /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/Dispatcher.cs:77)
Firebase.ExceptionAggregator:Wrap(Action) (at /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/ExceptionAggregator.cs:112)
Firebase.Dispatcher:PollJobs() (at /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/Dispatcher.cs:123)
Firebase.Platform.FirebaseHandler:Update() (at /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/Unity/FirebaseHandler.cs:207)
Firebase.Platform.FirebaseMonoBehaviour:Update() (at /home/runner/work/firebase-unity-sdk/firebase-unity-sdk/app/platform/Unity/FirebaseMonoBehaviour.cs:45)

image

Seems to also happen with DELETEs

To Reproduce

It really happens randomly, I can't reproduce it on purpose

Expected behavior

No 500 code returned from server

System information

Shenrak commented 1 year ago

Could it be that i'm sending 14 queries at the same time and the server locks itself onto resources that causes Internal Errors ?

Shenrak commented 1 year ago

I have those logs in Supabase Dashboard's Logs image

acupofjose commented 1 year ago

Hm. 14 simultaneous queries shouldn't be enough to overwhelm the server. I've been trying to overwhelm my instance to reduplicate (32 simultaneous requests) and cannot duplicate your issue.

The only way I can see you hitting that error boundary is if the request failed in transport and received no response from the server.

Is the query functioning as expected? Is it possible you are instantiating a new supabase client on every request?

Shenrak commented 1 year ago

Hi, thank you for your dedication :)

After further testing, i was able to take a grisp of what's going on Seems like the issues are happening only if the unity editor window looses focus while the app is running I believe it is a unity-related bug regarding tasks and processes

I think that's related with this issue

I think (hope) that is wont cause any issue in production mode, i'll have to be extra careful That never happened with firebase tho (which i used before)