Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-265209

Switching to protocol "CONFIGURATION" causes race condition

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 1.20.2 Pre-release 1
    • 23w35a
    • None
    • Plausible
    • Networking
    • Important
    • Platform

      When starting configuration phase (doesn't matter if on login or when already playing), there is a race condition caused by how netty handles auto-read.

      Explanation

      When the client receives a ClientboundStartConfigurationPacket (PLAY packet), it immediately suspends inbound (= disables auto-reading in netty channel config), as the packet needs to be handled on the main thread.

      Disabling auto-read does prevent reading more packets – but the current packet "batch" still gets handled. These packets will get processed in the wrong handler, as the client didn't switch the packet handlers yet.

      This causing errors with my custom protocol implementation, but not with vanilla server for some reason (maybe because everything is delayed because of ticks there?).

      (If you want some actual reproduction code LMK)

      Solution

      When configuring serialization in "Connection#configureSerialization", add netty's built-in "FlowControlHandler" at the end of the pipeline. This solves all my problems when testing, as this flow control handler queues all packets (which would otherwise go to the packet handler) and waits for auto-reading to be turned on again.

            boq [Mojang] Bartosz Bok
            booky10 booky 10
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: