FabianTerhorst / coreclr-module

Old alt:V CoreClr (.NET Core Common Language Runtime) community made module. New: https://github.com/altmp/coreclr-module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AltAsync.OnScriptRpc throws weird IO exception when either client emits with parameters or server try to answer

duydang2311 opened this issue · comments

Consider below code:

  • When the client emits with parameters, it throws the exception immediately, hence why the message is not logged.
  • When the client emits without parameters, it logs the message and throws the exception when executing e.Answer("OK");
AltAsync.OnScriptRpc += (e, player, name, args, answerId) =>
{
    Console.WriteLine("This should log if args is null"); 
    e.Answer("OK"); // executing this line throws IO exception
    return Task.CompletedTask;
};

The exception looks like this:

[72521:72521:20231029,032214.453563:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[72521:72521:20231029,032214.453675:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)

I have a workaround to replicate async event handler using Alt.OnScriptRPC instead, but may throw exception if incorrectly used.

Alt.OnScriptRPC += async (e, player, name, args, answerId) =>
{
    e.WillAnswer();
    await Task.Delay(1000);
    
    // Must not use e.Answer here or it throws the exact exception like above
    // e.Answer("After 1s");

    // Correct: use player.EmitRPCAnswer to answer
    player.EmitRPCAnswer(answerId, "After 1s", null);
};

@duydang2311 can u check it please with dev version 15.0.202-dev

There are some issues with the new version, seems like I won't be able to quickly check this.

I just updated the module and nuget. Now the same warning appears after resource is started and the server exits after segmentation fault. I don't load any resources at all.

[19:55:25] alt:V Server 15.0-dev912 (dev)
[19:55:25] Starting Dev Server on [::]:7788
[19:55:25] Required server permissions:
[19:55:25] Optional server permissions:
[19:55:25] Starting HTTP server on [::]:7788
[17760:17760:20231130,195525.919295:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[17760:17760:20231130,195525.919380:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
[19:55:25] Main thread started (ThreadId: 17750)
[19:55:25] EntityStreamer thread started (ThreadId: 17785)
[19:55:25] SyncSend thread started (ThreadId: 17787)
[19:55:25] SyncSend thread started (ThreadId: 17788)
[1]    17750 segmentation fault (core dumped)  ./altv-server

Version:

  • Server: 15.0-dev912
  • Nuget: 15.0.202-dev

already suggested a change. Better wait before its implemented.

@duydang2311 can u check it please with dev version 15.0.202-dev

public class FactionWritable : IWritable
   {
       public string Id { get; set; }
       public string Leader { get; set; }
       public string Name { get; set; }
       public string Acronym { get; set; }
       public ushort Type { get; set; }
       public string Color { get; set; }
       public string Description { get; set; }
   
       public void OnWrite(IMValueWriter writer)
       {
           try
           {
               writer.BeginObject();
               writer.Name("Id");
               writer.Value(Id);
               writer.Name("Name");
               writer.Value(Name);
               writer.Name("Acronym");
               writer.Value(Acronym);
               writer.Name("Type");
               writer.Value(Type);
               writer.Name("Color");
               writer.Value(Color);
               writer.Name("Description");
               writer.Value(Description);
               writer.Name("Leader");
               writer.Value(Leader);
               writer.EndObject();
           } catch (Exception e)
           {
               Console.WriteLine(e);
           }
       }
   }

  private async Task OnScriptRpc(IScriptRPCEvent @event, IPlayer target, string name, object[] args, ushort answerId)
   {
       /*var factionCollection = await _databaseService.Database
           .GetCollection<Faction>("factions")
           .FindAsync(faction => faction.Id == ObjectId.Parse("657adcabfe0bdd5e055d9f68"));
           
       var faction = await factionCollection.FirstOrDefaultAsync();
           
       if (faction is null)
           return;
       */
       FactionWritable factionWritable = new()
       {
           Id = "faction.Id.ToString()",
           Name = "faction.Name",
           Acronym = "faction.Acronym",
           Type = 1,
           Color = "faction.Color",
           Description = "faction.Description",
           Leader = "faction.Leader.ToString()"
       };
       
       @event.Answer(factionWritable);
       
       Alt.LogInfo("Send faction writable");
   }
[16:35:09] Execution of AltV.Net.Async.Events.ScriptRpcAsyncDelegate threw an error: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exce
ption.
   at AltV.Net.Async.AsyncScriptRpcEvent.Answer(Object answer)
   at Armonia.Server.Event.FactionEvent.OnScriptRpc(IScriptRPCEvent event, IPlayer target, String name, Object[] args, UInt16 answerId) in C:\Users\ruben\Desktop\armonia-roleplay\a
rmonia-gamemode\Armonia.Server\src\Event\FactionEvent.cs:line 69
   at AltV.Net.Async.AsyncEventHandler`1.ExecuteEventAsync(TEvent subscription, Func`2 callback)

tested on alt:V Server 15.0-dev969 (dev)

also, when awaiting my query (without mock) it doesn't crash but doesn't emit the answer as well

pls try it with nuget 15.0.205-dev

fixed with dev 15.0.207

also fixed with all 16.0.* versions

Well, I just tried this out with 16.0.7-dev and same issue still unfortunately.
The behaviour this time is a bit different, it crashes without needing to call Answer, as you see the empty event handler below.

AltAsync.OnScriptRpc += (e, player, name, args, answerId) =>
{
    return Task.CompletedTask;
};
[17119:17119:20231226,144834.100949:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[17119:17119:20231226,144834.101032:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)

Specifications:

  • Server: 16.0-dev16.
  • Nuget: 16.0.7-dev.
  • OS: Arch Linux.
  • .NET 8.