KitsuneLab-Development / K4-System

K4-Systems is a plugin that enhances the server with features such as a playtime tracker, statistical records, and player ranks. Additionally, it includes VIP functions and admin commands for added functionality.
GNU General Public License v3.0
104 stars 34 forks source link

[BUG] This MySqlConnection is already in use #134

Closed csportalsk closed 7 months ago

csportalsk commented 7 months ago

CSSv154, K4v3.3.0, Metamod:Source version 2.0.0-dev+1280, game_type 0, game_mode 1, Linux After update -> v3.3.0 errors on log

[EROR] (cssharp:Core) Error invoking callback
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.AggregateException: One or more errors occurred. (This MySqlConnection is already in use. See https://fl.vu/mysql-conn-reuse)
 ---> System.InvalidOperationException: This MySqlConnection is already in use. See https://fl.vu/mysql-conn-reuse
   at MySqlConnector.Core.ServerSession.StartQuerying(ICancellableCommand command) in /_/src/MySqlConnector/Core/ServerSession.cs:line 289
   at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 50
   at MySqlConnector.MySqlCommand.ExecuteReaderAsync(CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 357
   at K4System.Database.ExecuteReaderAsync(String query, MySqlParameter[] parameters)
   at K4System.ModuleRank.<>c__DisplayClass7_0.<<OnCommandTop>b__0>d.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at K4System.ModuleRank.OnCommandTop(CCSPlayerController player, CommandInfo info)
   at CounterStrikeSharp.API.Core.BasePlugin.<>c__DisplayClass41_0.<AddCommand>b__0(Int32 i, IntPtr ptr) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/BasePlugin.cs:line 260
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at CounterStrikeSharp.API.Core.FunctionReference.<>c__DisplayClass3_0.<.ctor>b__0(fxScriptContext* context) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/FunctionReference.cs:line 82
K4ryuu commented 7 months ago

Note for myself about the error:

The problem caused by any MySQL query that is being .Wait()-ed. Those causes deadlocks in the connection reuse, so all of them should be changed to use custom async functions with callback invoke to continue code on main thread (prevent non-main thread problems also)

K4ryuu commented 7 months ago

Greetings, The problem has been fixed hopefully, but if you encounter the problem again, please re-open this issue. Appreciate it!