Finally found the core of this issue.
It’s a unity internal exception that does not surface to the catch block.
Here’s the error
1982 2314 Unity Unobserved task exception: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Connection failed: Socket closed during connection attempt: WebsocketUndefined.) ---> Unity.Services.Wire.Internal.ConnectionFailedException: Connection failed: Socket closed during connection attempt: WebsocketUndefined.
1982 2314 Unity at Unity.Services.Wire.Internal.Client.ConnectAsync () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.T
1982 2314 Unity Unobserved task exception: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Connection failed: Socket closed during connection attempt: WebsocketUndefined.) ---> Unity.Services.Wire.Internal.ConnectionFailedException: Connection failed: Socket closed during connection attempt: WebsocketUndefined.
1982 2314 Unity at Unity.Services.Wire.Internal.Client.ConnectAsync () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.T
1982 2314 Unity Unobserved task exception: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Connection failed: Socket closed during connection attempt: WebsocketUndefined.) ---> Unity.Services.Wire.Internal.ConnectionFailedException: Connection failed: Socket closed during connection attempt: WebsocketUndefined.
1982 2314 Unity at Unity.Services.Wire.Internal.Client.ConnectAsync () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.T
1982 2314 Unity Unobserved task exception: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Connection failed: Socket closed during connection attempt: WebsocketUndefined.) ---> Unity.Services.Wire.Internal.ConnectionFailedException: Connection failed: Socket closed during connection attempt: WebsocketUndefined.
1982 2314 Unity at Unity.Services.Wire.Internal.Client.ConnectAsync () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.T
1982 2314 Unity Unobserved task exception: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Connection failed: Socket closed during connection attempt: WebsocketUndefined.) ---> Unity.Services.Wire.Internal.ConnectionFailedException: Connection failed: Socket closed during connection attempt: WebsocketUndefined.
1982 2314 Unity at Unity.Services.Wire.Internal.Client.ConnectAsync () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.T
1982 2314 Unity Unobserved task exception: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Connection failed: Socket closed during connection attempt: WebsocketUndefined.) ---> Unity.Services.Wire.Internal.ConnectionFailedException: Connection failed: Socket closed during connection attempt: WebsocketUndefined.
1982 2314 Unity at Unity.Services.Wire.Internal.Client.ConnectAsync () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.T
1982 2314 Unity Unobserved task exception: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Connection failed: Socket closed during connection attempt: WebsocketUndefined.) ---> Unity.Services.Wire.Internal.ConnectionFailedException: Connection failed: Socket closed during connection attempt: WebsocketUndefined.
1982 2314 Unity at Unity.Services.Wire.Internal.Client.ConnectAsync () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
1982 2314 Unity at System.Threading.Tasks.AwaitTaskContinuation.RunCallback (System.T
1982 2165 Unity CreateSession timeout: System.TimeoutException: UGS task timed out
1982 2165 Unity at Lobby_Manager.AwaitWithTimeout[T] (System.Threading.Tasks.Task`1[TResult] task, System.Int32 timeoutMs) [0x00000] in <00000000000000000000000000000000>:0
1982 2165 Unity at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
1982 2165 Unity at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <00000000000000000000000000000000>:0
1982 2165 Unity at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0
1982 2165 Unity at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
1982 2165 Unity --- End of stack trace from previous location where exception was thrown ---
1982 2165 Unity
1982 2165 Unity at Lobby_Manager.createSession (System.String lobbyName, System.Boolean onlyFriends, System.Boolean wantVC) [0
This is the entire error log from logcat and it says its a websocket error for some reason even though i have a stable internet connection.
Here’s my code
public async Task createSession(string lobbyName, bool onlyFriends,bool wantVC)
{
SessionOptions options = new SessionOptions()
{
//change this after game completion
IsPrivate = onlyFriends,
MaxPlayers = maxPlayers,
SessionProperties = new Dictionary<string, SessionProperty>
{
{strings.gameStarted.ToString(),new SessionProperty(strings.False.ToString(),index:PropertyIndex.String1) },
{strings.map.ToString(),new SessionProperty(null) },
{strings.lobbyname.ToString(),new SessionProperty(lobbyName) },
{strings.wantVC.ToString(),new SessionProperty(wantVC.ToString()) }
}
}.WithDistributedAuthorityNetwork();
playerName = project_Networkmanager.instance.getPlayerName();
try
{
onLobbyCreation?.Invoke(this, EventArgs.Empty);
Debug.Log("Creating session");
currentSession = await AwaitWithTimeout(MultiplayerService.Instance.CreateSessionAsync(options),30000);
Debug.Log("Creating session successfully");
//setting player propsadwad
await setPlayerProps(wantVC);
registerLobbyEvents();
//await currentSession.RefreshAsync();
onLobbyCreationCompleted?.Invoke(this, EventArgs.Empty);
}
catch (OperationCanceledException e)
{
Debug.Log(e);
onLobbyCreationFailed?.Invoke(this, EventArgs.Empty);
}
catch (TimeoutException e)
{
Debug.LogError("CreateSession timeout: " + e);
onLobbyCreationFailed?.Invoke(this, EventArgs.Empty);
}
catch (Exception e)
{
onLobbyCreationFailed?.Invoke(this, EventArgs.Empty);
Debug.Log("Cant Create a Sesion " + e);
}
}
this is called from an event which get triggered whenever an ad is closed or if they purchased ads then the event is called with null params like this
private void createLobby(object sender, EventArgs e)
{
Debug.Log("Working");
createLobby();
}
public async void createLobby()
{
try
{
await Lobby_Manager.instance.createSession(lobbyName.text, onlyFriends.isOn, wantVCToggle.isOn);
}
catch (Exception e)
{
onLobbyCreationFailed(null, null);
Debug.Log(e);
}
}
I don’t know whether this is my code issue or a unity bug that suppress this error and i found this using this line of code.
TaskScheduler.UnobservedTaskException += (s, e) =>
{
Debug.LogError("Unobserved task exception: " + e.Exception);
};
This behaviour is so random and it’s breaking a lot of my players game. yes my game is on playstore and players are not happy about it.
Hope this info helps and thanks in advance.