question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`confluentinc/cp-kafka:6.2.2` and `7.0.1` don't work with `KafkaContainer`

See original GitHub issue

This issue has been originally reported by @simonbasle in our Testcontianers Slack.

While we initially thought this is related to GitHub Actions, it seems this is a general incompatibility of KafkaContainer with cp-kafka images >= 6.2.2.

During container startup, our InternalCommandPortListeningCheck will fail with logs along the lines of:

17:57:13.528 WARN  org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck - An exception while executing the internal check: Container.ExecResult(exitCode=137, stdout=, stderr=Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to 127.0.0.1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Cannot assign requested address.
/bin/bash: connect: Cannot assign requested address
/bin/bash: /dev/tcp/localhost/9093: Cannot assign requested address

Subsequently, our exec is failing:

17:57:13.532 INFO  🐳 [confluentinc/cp-kafka:6.2.2] - Container confluentinc/cp-kafka:6.2.2 started in PT2.1713743S
17:57:13.532 DEBUG org.testcontainers.containers.ExecInContainerPattern - /hungry_newton: Running "exec" command: kafka-configs --alter --bootstrap-server BROKER://994010ec6ac8:9092 --entity-type brokers --entity-name 1 --add-config advertised.listeners=[PLAINTEXT://127.0.0.1:62036,BROKER://994010ec6ac8:9092]
17:57:13.669 ERROR 🐳 [confluentinc/cp-kafka:6.2.2] - Could not start container
com.github.dockerjava.api.exception.ConflictException: Status 409: {"message":"Container 994010ec6ac8c3cb2ff554a849fdba13b8e38ec6798585d648a766b601fbfd6c is not running"}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sergey-morenetscommented, May 15, 2022

Hi

Confirmed that TestContainers 16.3 fails to start even GenericContainer for cp-kafka:7.1.1:

kafka = new GenericContainer<>(DockerImageName.parse("confluentinc/cp-kafka:7.1.1"))
	.withEnv("KAFKA_PROCESS_ROLES", "broker,controller").withEnv("KAFKA_NODE_ID", "1")
	.withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT")
	.withEnv("KAFKA_ADVERTISED_LISTENERS", "PLAINTEXT://kafka:9092")
	.withEnv("KAFKA_CONTROLLER_QUORUM_VOTERS", "1@kafka:9093")
	.withEnv("KAFKA_LISTENERS", "PLAINTEXT://kafka:9092,CONTROLLER://kafka:9093")
	.withEnv("KAFKA_CONTROLLER_LISTENER_NAMES", "CONTROLLER")
	.withExposedPorts(9092);

Log output:

[testcontainers-wait-0] WARN org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck - An exception while executing the internal check: Container.ExecResult(exitCode=137, stdout=, stderr=Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connection to 127.0.0.1 failed: Connection refused.
Ncat: Trying next address...
Ncat: Cannot assign requested address.
/bin/bash: connect: Cannot assign requested address
/bin/bash: /dev/tcp/localhost/9092: Cannot assign requested address
)
[main] INFO 🐳 [confluentinc/cp-kafka:7.1.1] - Container confluentinc/cp-kafka:7.1.1 started in PT0.6145648S
2reactions
simonbaslecommented, Dec 13, 2021

Thanks for your help in debugging this @kiview !

On a side note, about the Ncat log, there is still some such logs visible if you enable trace logging, even with 6.2.1… That’s because of some polling aspect, I’m assuming.

So right after these logs, we get a success with 6.2.1:

    /bin/bash: connect: Cannot assign requested address
    /bin/bash: /dev/tcp/localhost/9093: Cannot assign requested address

    [2021-12-13 12:57:56,321] [testcontainers-wait-0] [org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck] TRACE Check for [9093, 2181] took PT8.449S. Result code '0', stdout message: '/proc/net/tcp:   3: 00000000:2385 00000000:0000 0A 00000000:00000000 00:00000000 00000000  1000        0 36725 1 0000000000000000 100 0 0 10 0                     
    /proc/net/tcp:   4: 00000000:0885 00000000:0000 0A 00000000:00000000 00:00000000 00000000  1000        0 36445 1 0000000000000000 100 0 0 10 0                     
    /proc/net/tcp:   5: 0100007F:AC38 0100007F:0885 01 00000000:00000000 00:00000000 00000000  1000        0 36641 1 0000000000000000 20 4 10 10 -1                    
    /proc/net/tcp:   6: 0100007F:0885 0100007F:AC38 01 00000000:00000000 00:00000000 00000000  1000        0 36642 1 0000000000000000 20 4 21 10 -1       

But with 6.2.2 we get an error:

    /bin/bash: connect: Cannot assign requested address
    /bin/bash: /dev/tcp/localhost/9093: Cannot assign requested address

    [2021-12-13 12:19:46,251] [testcontainers-wait-0] [org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck] TRACE Check for [9093, 2181] took PT3.331S. Result code '137', stdout message: ''
    [2021-12-13 12:19:46,251] [testcontainers-wait-0] [org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck] WARN An exception while executing the internal check: Container.ExecResult(exitCode=137, stdout=, stderr=Ncat: Version 7.70 ( nmap.org/ncat )
Read more comments on GitHub >

github_iconTop Results From Across the Web

Kafka Containers - Testcontainers for Java
Create a KafkaContainer to use it in your tests: ... The correspondence between Confluent Platform versions and Kafka versions can be seen in...
Read more >
Advanced Testing Techniques for Spring for Apache Kafka
The @Testcontainers annotation manages the lifecycle of the KafkaContainer . You can create a test topic utilizing Spring for Kafka's Admin API ...
Read more >
kafka after reconnect with docker: Connection to node could ...
The reconnect problem happen sometimes (is not regular) and the kafka container remain up but disconnected from the net. This is my docker- ......
Read more >
Testing Kafka containers with Testcontainers: There and back ...
I Don't Always Test My Streams, But When I Do, I Do it in Production (Viktor ... confluent. 1k views. •. 62 slides....
Read more >
How to Set Up Kafka Integration Test - Grape Up
TestContainers is an open-source Java library specialized in providing all needed solutions ... implementation( "io.confluent:kafka-avro-serializer:6.1.0" ).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found