Kafka server running into java.net.SocketException: Invalid argument exception

487 Views Asked by At

I am trying to start up Kafka server locally on a macos with m1 chip. I followed the guide from the official kakfa quickstart(https://kafka.apache.org/quickstart). Zookeeper starts up fine but bin/kafka-server-start.sh config/server.properties is giving me socket invalid argument exception below:

[2023-01-30 09:22:55,790] ERROR Encountered an error while configuring the connection, closing it. (kafka.network.DataPlaneAcceptor)
java.net.SocketException: Invalid argument
    at java.base/sun.nio.ch.Net.setIntOption0(Native Method)
    at java.base/sun.nio.ch.Net.setSocketOption(Net.java:373)
    at java.base/sun.nio.ch.SocketChannelImpl.setOption(SocketChannelImpl.java:234)
    at java.base/sun.nio.ch.SocketAdaptor.setBooleanOption(SocketAdaptor.java:270)
    at java.base/sun.nio.ch.SocketAdaptor.setTcpNoDelay(SocketAdaptor.java:305)
    at kafka.network.Acceptor.configureAcceptedSocketChannel(SocketServer.scala:759)
    at kafka.network.Acceptor.accept(SocketServer.scala:737)
    at kafka.network.Acceptor.acceptNewConnections(SocketServer.scala:703)
    at kafka.network.Acceptor.run(SocketServer.scala:645)
    at java.base/java.lang.Thread.run(Thread.java:829)

I have tried:

  1. Double checking that no other application is using the same port
  2. Use a different JDK (from openjdk17 to openjdk 11 and back to 17)
  3. Rebooted my machine
  4. Clear up kafka related log folder under /tmp
  5. Rebooted my machine
  6. Used a lower version (3.2.1) of kafka tarball (since that one worked for me before but now it also runs into the same socket issue)
  7. Change zookeeper port from 2181 to something else
2

There are 2 best solutions below

1
Pupusa On

Turns out to be an antivirus issue. Sorry for the false alarm.

1
M.Vasyshev On

I saw the same exception when starting kafka server installed from brew on mac with intel chip.

In my case that might not have been antivirus issue, I solved the problem configuring listener in server.properties file:

listeners=PLAINTEXT://localhost:9092