Skip to content

Monitor WebSocket code 1006 is incorrectly reported as "Message too big" #168

Description

@FlorianBarbe

Summary

During normal Unity Play/Stop cycles, the monitor WebSocket can close with code 1006.

The middleware currently handles close codes 1006 and 1009 in the same way and displays:

[ERR 1006] Message too big!
Message: ArrayBuffer {
  (detached),
  [byteLength]: 0
}
Message size: 45 bytes

This message is misleading because:

  • 1006 means an abnormal WebSocket closure.
  • 1009 is the actual code for a message that is too large.
  • The reported message was only 45 bytes.
  • The raw ArrayBuffer is already detached when it is displayed.

The error is visible even with:

VERBOSE=false
EXTRA_VERBOSE=false

Steps to reproduce

  1. Start GAMA.
  2. Start the SIMPLE webplatform.
  3. Start Unity Play Mode.
  4. Wait approximately 20 seconds.
  5. Stop Unity Play Mode.
  6. Wait approximately 10 seconds.
  7. Repeat the Play/Stop cycle.

Actual behavior

The middleware displays:

[ERR 1006] Message too big!
ArrayBuffer {
  (detached),
  [byteLength]: 0
}
Message size: 45 bytes

Expected behavior

  • Handle code 1006 separately from 1009.
  • Do not display Message too big for code 1006.
  • Do not log the raw ArrayBuffer.
  • Keep normal Unity Play/Stop monitor closures out of non-verbose error logs.
  • Continue displaying a real error for code 1009.

Local validation

To test a possible solution before opening this issue, I created a local branch of the webplatform:

test/monitor-close-logging

I modified the monitor WebSocket close-handling logic in MonitorServer.ts in order to test whether these misleading errors could be removed without affecting the normal Unity Play/Stop workflow.

The local changes were limited to the monitor close handler:

  • the close reason and message size are copied immediately inside the WebSocket callback;
  • close code 1006 is handled separately from 1009;
  • code 1006 is logged at debug level instead of being reported as Message too big;
  • code 1009 remains the actual oversized-message error;
  • the raw ArrayBuffer is no longer passed directly to the logger.

After applying these changes, I repeated the same Unity Play/Stop scenario twice.

The following messages no longer appeared:

ERR 1006
Message too big
ArrayBuffer
detached
Message size

The test therefore suggests that separating 1006 from 1009 and copying the close data immediately is enough to remove this misleading error spam from normal logs.

Suggested fix

A potential fix for this issue could follow this approach:

  1. In MonitorServer.ts, copy the close reason and byte length immediately at the beginning of the WebSocket close callback.
  2. Handle close code 1006 in its own case.
  3. Do not label code 1006 as Message too big.
  4. Log expected short-lived 1006 monitor closures at debug level, so they do not appear when verbose logging is disabled.
  5. Keep code 1009 as the real oversized-message error.
  6. Avoid logging the raw uWebSockets.js ArrayBuffer, because it may already be detached when the logger formats it.
  7. Add or update tests to verify that:
    • a 1006 closure does not produce a Message too big error;
    • a real 1009 closure still produces an oversized-message error;
    • normal Unity Play/Stop cycles do not emit detached-buffer logs.

Other PlayerManager warnings still appear during the same Play/Stop workflow. They are separate from this monitor logging issue and were intentionally not modified during this local test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions