Sanae6 / SmoOnlineServer

Official server for Super Mario Odyssey: Online
https://discord.gg/jYCueK2BqD
103 stars 24 forks source link

Large amount of warnings surrounding async/await #14

Closed luludotdev closed 1 year ago

luludotdev commented 2 years ago

When opening the project in VS2022, there are a large amount of CS4014 warnings.

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the await operator to the result of the call.

I wanted to know if these are intentional, in which case they should be explicitly suppressed. Otherwise they should probably be fixed with await calls.

Istador commented 2 years ago

There are also other warnings. Build log from the Github Action:

Build and deploy #2 / Build and push
#19 [linux/amd64 build 6/6] RUN  dotnet  publish      ./Server/Server.csproj      -r debian.11-`echo amd64 | sed 's@^amd@x@'`      -c Release      -o ./out/      --no-restore      --self-contained      -p:publishSingleFile=true  ;
#19 0.462 Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
#19 0.462 Copyright (C) Microsoft Corporation. All rights reserved.
#19 0.462 
#19 7.185   Shared -> /app/Shared/bin/Release/net6.0/Shared.dll
#19 9.800 /app/Server/Client.cs(12,14): warning CS0660: 'Client' defines operator == or operator != but does not override Object.Equals(object o) [/app/Server/Server.csproj]
#19 9.800 /app/Server/Client.cs(12,14): warning CS0661: 'Client' defines operator == or operator != but does not override Object.GetHashCode() [/app/Server/Server.csproj]
#19 9.800 /app/Server/Client.cs(26,12): warning CS8618: Non-nullable property 'Server' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [/app/Server/Server.csproj]
#19 9.801 /app/Server/Server.cs(35,21): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/Server/Server.csproj]
#19 9.801 /app/Server/Server.cs(283,17): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/Server/Server.csproj]
#19 9.801 /app/Server/Server.cs(291,39): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/Server/Server.csproj]
#19 9.801 /app/Server/Server.cs(307,9): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/Server/Server.csproj]
#19 9.801 /app/Server/Program.cs(98,21): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/Server/Server.csproj]
#19 9.802 /app/Server/Program.cs(112,13): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/Server/Server.csproj]
#19 9.802 /app/Server/Program.cs(131,13): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/Server/Server.csproj]
#19 9.802 /app/Server/Program.cs(144,17): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/Server/Server.csproj]
#19 9.802 /app/Server/Program.cs(501,1): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/Server/Server.csproj]
#19 9.802 /app/Server/Program.cs(117,44): warning CS8600: Converting null literal or possible null value to non-nullable type. [/app/Server/Server.csproj]
#19 9.802 /app/Server/Program.cs(119,17): warning CS8604: Possible null reference argument for parameter 'source' in 'bool Enumerable.Contains(IEnumerable source, int value)'. [/app/Server/Server.csproj]
#19 9.802 /app/Server/Program.cs(128,64): warning CS8605: Unboxing a possibly null value. [/app/Server/Server.csproj]
#19 9.808 /app/Server/Program.cs(139,62): warning CS8605: Unboxing a possibly null value. [/app/Server/Server.csproj]
#19 9.808 /app/Server/Program.cs(460,17): warning CS8600: Converting null literal or possible null value to non-nullable type. [/app/Server/Server.csproj]
#19 9.808 /app/Server/Program.cs(459,41): warning CS8600: Converting null literal or possible null value to non-nullable type. [/app/Server/Server.csproj]
#19 9.809 /app/Server/Program.cs(460,75): warning CS8602: Dereference of a possibly null reference. [/app/Server/Server.csproj]
#19 11.22   Server -> /app/Server/bin/Release/net6.0/debian.11-x64/Server.dll
#19 12.93   Server -> /app/out/
TheUbMunster commented 1 year ago

Most (if not all) of those I believe are done as intentional fire-and-forgets. Could probably be fixed with #pragma warning disable CS4014 / #pragma warning restore, But since fire-and-forget async method calls eat exceptions, maybe add exception logging via appending .ContinueWith(x => { if (x.Exception != null) { consoleLogger.Error(x.Exception.ToString()); } }) to each async call, or get rid of the warnings by changing the return type of async method declarations to async void instead of async Task (however changing to void will make the .ContinueWith thing not work anymore. For Task.Run, probably best to do continuewith and pragma thing

TheUbMunster commented 1 year ago

See #20