Azure spring boot socket.io Cannot assign requested address issue

249 views Asked by At

I deployed my Spring Boot Socket.IO application to Azure Web App for Containers.

In Docker, I am using port 80 for Spring and port 443 for Socket.IO.

I have tried using the Azure Virtual IP address and default domain values for the hostname, but I keep getting the following error:

Caused by: java.net.BindException: Cannot assign requested address
2023-07-15T15:49:58.391590007Z at java.base/sun.nio.ch.Net.bind0(Native Method) ~[na:na]
2023-07-15T15:49:58.391594407Z at java.base/sun.nio.ch.Net.bind(Net.java:555) ~[na:na]
2023-07-15T15:49:58.391598807Z at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337) ~[na:na]
2023-07-15T15:49:58.391606707Z at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294) ~[na:na]
2023-07-15T15:49:58.391614307Z at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:141) ~[netty-transport-4.1.94.Final.jar!/:4.1.94.Final]
2023-07-15T15:49:58.391618807Z at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:562) ~[netty-transport-4.1.94.Final.jar!/:4.1.94.Final]
2023-07-15T15:49:58.391623407Z at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1334) ~[netty-transport-4.1.94.Final.jar!/:4.1.94.Final]
2023-07-15T15:49:58.391627908Z at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:600) ~[netty-transport-4.1.94.Final.jar!/:4.1.94.Final]
1

There are 1 answers

0
Suresh Chikkam On

Mostly, the above error occurs when the port that you are trying to bind is already in use. Bind the Socket.IO server to a different port that doesn't conflict with the default ports used by Azure Web App for Containers.

  • I tried a sample Chat application using a different port like 8080 for Socket.IO.

I used java 11 version for the application(springboot).

Dependencies:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-rsocket</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.corundumstudio.socketio</groupId>
            <artifactId>netty-socketio</artifactId>
            <version>2.0.3</version>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
  • I am able to run my application locally and converted into Docker image and then containerized.

enter image description here

In Docker container: enter image description here

ChatApplication: enter image description here

  • Created ACR and then pushed into it from docker.

enter image description here

  • I am able to see the container which I pushed to Azure container registry.

enter image description here

Then, I created a webapp that gets deployed from ACR and configures the Ports:

  • Port 80 (HTTP) is open for incoming traffic.
  • Port 443 (HTTPS) is open for incoming traffic.

enter image description here

Container Logs: enter image description here