Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThreadLog captures and writes out non-mirror related logs #3696

Open
handzlikchris opened this issue Dec 7, 2023 · 1 comment
Open

ThreadLog captures and writes out non-mirror related logs #3696

handzlikchris opened this issue Dec 7, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@handzlikchris
Copy link

We're seeing debug-error messages coming from our app code that have Mirror at the bottom of the stack-trace.

eg.

<correct stack trace begins here>
Mirror.ThreadLog:OnLateUpdate()
Mirror.NetworkLoop:NetworkLateUpdate()

The messages are also duplicated, we'll also get another one with correct stack trace.
eg.

Test Thread Log
UnityEngine.Debug:LogError (object)
UniTaskMirrorTest/<>c:<Test>b__0_0 () (at Assets/#Project/Scripts/UniTaskMirrorTest.cs:11)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()

And mirror will produce

[T3029] Test Thread Log
UnityEngine.Debug:LogError (object)
UniTaskMirrorTest/<>c:<Test>b__0_0 () (at Assets/#Project/Scripts/UniTaskMirrorTest.cs:11)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()

UnityEngine.Debug:LogError (object)
Mirror.ThreadLog:OnLateUpdate () (at Assets/Mirror/Core/Threading/ThreadLog.cs:97)
Mirror.NetworkLoop:NetworkLateUpdate () (at Assets/Mirror/Core/NetworkLoop.cs:206)

It seems to be down to how ThreadLog attaches itself as a log-handler for threaded messages in Mirror.ThreadLog.Initialize via
Application.logMessageReceivedThreaded += OnLog;

And then pumps the logs out in Mirror.ThreadLog.OnLateUpdate - which is why we're seeing them with Mirror stack-trace alongside out normal threaded logging.

Repro

  1. Create app logger that attaches to Application.logMessageReceivedThreaded += HandleLog;
  2. Add following behaviour
public class UniTaskMirrorTest : MonoBehaviour
{
    void Start()
    {
        Task.Run(() =>
        {                
            Debug.LogError("Test Thread Log");
        });
    }
}
  1. Build and run
  2. Mirror logger and custom-app logger will print error

Expected behavior
I'd expect Mirror ThreadLog to only log its own messages

Desktop (please complete the following information):

  • OS: Windows
  • Build target: Standalone
  • Unity version: 2022.1.23
  • Mirror branch: v83.2.1
@MrGadget1024 MrGadget1024 added the bug Something isn't working label Jan 2, 2024
@miwarnec
Copy link
Collaborator

miwarnec commented Jan 2, 2024

@handzlikchris interesting.
feel free to disable it for now, it's only needed if you use ThreadedTransports.
we'll look into a fix in a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants