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.

Method of exposing UDP port changed in 1.16.0

See original GitHub issue

I am upgrading from: TestContainers 1.15.3 -> 1.16.2 Docker-Java 3.2.8 -> 3.2.12

In order to expose a UDP port, users are required to access the underlying docker-java command, and modify it to expose the desired port. In my project I am doing this using a custom container class and overwriting the configure() method as follows:

public class KerberosContainer extends GenericContainer<KerberosContainer> {
    @Override
    protected void configure() {
        withExposedPorts(99, 464, 749); //TCP ports
        withNetworkAliases(KRB5_KDC);
        withCreateContainerCmdModifier(cmd -> {
            List<ExposedPort> ports = new ArrayList<>();
            for (ExposedPort p : cmd.getExposedPorts()) {
                ports.add(p);
            }
            ports.add(new ExposedPort(99, InternetProtocol.UDP));
            cmd.withExposedPorts(ports);
	    cmd.withHostName(KRB5_KDC);
        });
    }
}

Once the container is started, I try to extract the mapped port using the InspectContainerResponse object as follows:

    @Override
    protected void containerIsStarted(InspectContainerResponse containerInfo) {
        NetworkSettings networkSettings = containerInfo.getNetworkSettings();
        Ports ports = networkSettings.getPorts();
        Map<ExposedPort, Binding[]> map = ports.getBindings();
        Binding[] bindings = map.get(new ExposedPort(99, InternetProtocol.UDP));
        Binding binding = bindings[0];  //NullPointerException
        String udp99 = binding.getHostPortSpec();

        udp_99 = Integer.valueOf(udp99);
    }

A NullPointerException is thrown because the withCreateContainerCmdModifier was not honored. This is apparent when inspecting the container created directly with docker:

Screen Shot 2021-11-09 at 1 39 18 PM

And printing out the contents of the bindings map at runtime

{
  749/tcp=[Lcom.github.dockerjava.api.model.Ports$Binding;@3bcb01f9, 
  464/tcp=[Lcom.github.dockerjava.api.model.Ports$Binding;@defb0e3a, 
  99/tcp=[Lcom.github.dockerjava.api.model.Ports$Binding;@15c64f5f, 
  99/udp=null, 
  88/tcp=null
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
bsideupcommented, Nov 10, 2021

Putting “wontfix” here because it isn’t a breaking change but an assumption that got changed. We never guaranteed that we will bind ports that were added through withCreateContainerCmdModifier and going that route means that now you are dealing with Docker’s low level API and need to understand how it behaves.

0reactions
kiviewcommented, Nov 12, 2021

Thanks @KyleAure, your help is much appreciated 🙌

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using AWS NLB manually targeting an EKS Service exposing ...
Problem encountered with EKS 1.16. If we try to create a service of type Network Load Balancer (NLB) for UDP traffic we can...
Read more >
Nginx-Ingress Helm Deployment --tcp-services-configmap ...
I'm trying to do TCP/UDP port-forwarding with an ingress. ... Here you can clearly see its an argument of the controller: --tcp-services-configmap ...
Read more >
The default dynamic port range for TCP/IP has changed in ...
This article describes the changes to the default dynamic port range for TCP/IP in Windows Vista and in Windows Server 2008.
Read more >
Hacking VoIP Exposed - Black Hat
a popular way of finding bugs and vulnerabilities. • Fuzzing involves creating different types of packets for a protocol which contain data that...
Read more >
PgBouncer changelog
Change auth_type in sample pgbouncer.ini to md5 to match the built-in default. ... 2021-08-09 - PgBouncer 1.16.0 - “Fended off a jaguar”.
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