Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-14908

Sporadic "Address already in use" when starting kafka cluster embedded within tests

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Reopened
    • Major
    • Resolution: Unresolved
    • None
    • 3.8.0
    • unit tests
    • None

    Description

      We have an integration test suite that starts/stops a kafka cluster before/after each test.   Kafka is being started programmatically within the same JVM that is running the tests.

      Sometimes we get sporadic failures from with Kafka as it tries to bind the server socket.

      org.apache.kafka.common.KafkaException: Socket server failed to bind to 0.0.0.0:9092: Address already in use.
          at kafka.network.Acceptor.openServerSocket(SocketServer.scala:684)
          at kafka.network.Acceptor.<init>(SocketServer.scala:576)
          at kafka.network.DataPlaneAcceptor.<init>(SocketServer.scala:433)
          at kafka.network.SocketServer.createDataPlaneAcceptor(SocketServer.scala:247)
          at kafka.network.SocketServer.createDataPlaneAcceptorAndProcessors(SocketServer.scala:226)
          at kafka.network.SocketServer.$anonfun$new$31(SocketServer.scala:173)
          at kafka.network.SocketServer.$anonfun$new$31$adapted(SocketServer.scala:173)
          at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:575)
          at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:573)
          at scala.collection.AbstractIterable.foreach(Iterable.scala:933)
          at kafka.network.SocketServer.<init>(SocketServer.scala:173)
          at kafka.server.KafkaServer.startup(KafkaServer.scala:331) 

      Investigation has shown that the socket is in the timed_wait state from a previous test.

      I know Kafka supports ephemeral ports, but this isn't convenient to our use-case.  

      I'd like to suggest that Kafka is changed to set the SO_REUSEADDR on the server socket.  I believe this is standard practice for server applications that run on well known ports .

      I don't believe this change would introduce a backward compatibility concerns. 

       

      I will open a PR so that can be considered. Thank you.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kwall Keith Wall
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: