Class SelectorInvalidReceiveTest

java.lang.Object
org.apache.kafka.common.network.SelectorInvalidReceiveTest

public class SelectorInvalidReceiveTest extends Object
Tests for the Selector's handling of InvalidReceiveException thrown when a peer sends an oversized request. The behavior under test is transport-agnostic (it's driven by the size prefix read in NetworkReceive.readFrom(ScatteringByteChannel)), so this test deliberately uses a plaintext channel builder and is not part of SelectorTest's inheritance hierarchy.
  • Constructor Details

    • SelectorInvalidReceiveTest

      public SelectorInvalidReceiveTest()
  • Method Details

    • setUp

      @BeforeEach public void setUp()
    • tearDown

      @AfterEach public void tearDown()
    • testInvalidReceiveDelaysCloseWhenDelayConfigured

      @Test public void testInvalidReceiveDelaysCloseWhenDelayConfigured() throws Exception
      When a peer sends an oversized request that triggers InvalidReceiveException in NetworkReceive.readFrom(ScatteringByteChannel), the channel is parked in delayedClosingChannels for failedAuthenticationDelayMs before being closed — mirroring the authentication-failure path. This slows down attackers that issue oversized requests in tight loops without changing the eventual outcome (the connection is still closed).
      Throws:
      Exception
    • testInvalidReceiveClosesImmediatelyWhenDelayDisabled

      @Test public void testInvalidReceiveClosesImmediatelyWhenDelayDisabled() throws Exception
      When failedAuthenticationDelayMs is disabled, an InvalidReceiveException closes the channel immediately — preserving the pre-existing behavior for deployments that have not opted into the delay.
      Throws:
      Exception