We are upgrading our Spring Boot applications to Spring Boot 2.6.1. Spring
Boot 2.6.1 upgrade our Kafka dependency from 2.7.1 to 3.0.0.
After upgrading I'm getting a AccessDeniedException on all my tests using
@EmbeddedKafka.
Caused by: java.nio.file.AccessDeniedException:
C:\Temp\spring.kafka.ae934565-33bc-4073-ab06-59ce265490369531329615041832669
at
java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
at
java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
at
java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
at
java.base/sun.nio.fs.WindowsFileSystemProvider.newFileChannel(WindowsFileSystemProvider.java:121)
at java.base/java.nio.channels.FileChannel.open(FileChannel.java:298)
at java.base/java.nio.channels.FileChannel.open(FileChannel.java:357)
at org.apache.kafka.common.utils.Utils.flushDir(Utils.java:953)
at
org.apache.kafka.common.utils.Utils.atomicMoveWithFallback(Utils.java:941)
at
kafka.server.BrokerMetadataCheckpoint.liftedTree1$1(BrokerMetadataCheckpoint.scala:214)
at
kafka.server.BrokerMetadataCheckpoint.write(BrokerMetadataCheckpoint.scala:204)
I've been searching in the Kafka source code for the cause of the error and it
seems the Utils.flushDir is causing troubles on Windows.
On several places FileChannel.open(path, StandardOpenOption.READ) is called
which will always fail on Windows when path is a directory. See:
https://mail.openjdk.java.net/pipermail/nio-dev/2013-February/002123.html
Another example of failing code on Windows is the
kafka.log.LogManager.createAndValidateLogDirs method which calls the
Utils.flushDir(dir.toPath.toAbsolutePath.normalize.getParent) with a directory
as parm. This will always fail on Windows.
How can this be solved? (I can't find a related Kafka Jira issue)
More related reports:
https://stackoverflow.com/questions/70182684/failed-to-start-kafka-server-in-window/70183556
Regards,
Martijn de Bruijn
Software engineer