mux icon indicating copy to clipboard operation
mux copied to clipboard

the Wrapped Gorilla Websocket connection by Gorilla Mux, does not work within the docker container.

Open mindwingx opened this issue 10 months ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

the below Mux HandlerFunc works well.

func WsHandler(rw http.ResponseWriter, r *http.Request) {
	ws, err := upgradeConn.Upgrade(rw, r, nil)
	if err != nil {
		log.Println(err)
	}

	log.Println("connected to the ws ep.")

	conn := WsConn{ws}
	clients[conn] = WsConnDetail{}

	go WsListener(&conn)
}

Expected Behavior

but the WS connection is not available after building the application docker image and running the container. image

Steps To Reproduce

docker-compose

version: "3.8"
services:

  core:
    container_name: webrtc_service
    build:
      context: .
      dockerfile: Dockerfile
    image: rtc
    restart: always
    ports:
      - "8080:8080"
    networks:
      - admin-service
```

### Anything else?

 Dockerfile

```
FROM golang:1.21.6

WORKDIR /app

COPY . .

ENV GO111MODULE on
ENV GOPROXY https://goproxy.cn

# RUN go test -v .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main presenter/main.go
RUN chmod +x main

CMD ["/app/main"]
```

mindwingx avatar May 03 '24 17:05 mindwingx

What is the log output of WsHandler? Specifically, does upgradeConn.Upgrade return an error?

As a side note, there are bugs in WsHandler.

  • handler should return after logging error from upgradeConn.Upgrade.
  • data race on this line: clients[conn] = WsConnDetail{} Run application with the Data Race Detector and fix reported problems.

hulkingshtick avatar Aug 21 '24 17:08 hulkingshtick