Skip to content

Websock connection closing abnormally when running inside docker container  #43

@maheshkulkarni4

Description

@maheshkulkarni4

I am trying to run the graphqlws inside a docker container. The code is straight forward and if I test locally it works fine. My UI App is able to establish a Websocket connection and receive messages coming from Server.

But when I run inside docker, the path to reach my server is as follows.
Browser -> UI POD (https) -> nginx -> proxy to graphql/Server pod

I have already added the following headers in my Nginx to allow proper traffic

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "keep-alive, upgrade";
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
proxy_pass http://graphql;

But still, the following error is thrown immediately

time="2022-08-10T10:40:05Z" level=info msg="Created connection" prefix="graphqlws/connection/d2751293-304b-448c-8e44-0c97f108feec"                                                  ││ time="2022-08-10T10:40:49Z" level=warning msg="Closing connection" prefix="graphqlws/connection/d2751293-304b-448c-8e44-0c97f108feec" reason="websocket: close 1006 (abnormal closu ││ time="2022-08-10T10:41:19Z" level=info msg="Remove subscriptions" conn=d2751293-304b-448c-8e44-0c97f108feec prefix="graphqlws/subscriptions"                                        ││ time="2022-08-10T10:41:21Z" level=info msg="Closed connection" prefix="graphqlws/connection/d2751293-304b-448c-8e44-0c97f108feec"           
  • UI is accessing this with wss:// and nginx routes to http:// as its pod to pod traffic
  • I tried to Run the Server Application locally and able to access the endpoint on ws:// locally, it works perfectly fine.
  • I tried to port-forward the server pod and use connection with ws:// it did not work either. Same error as above is thrown.

Below is the handler implementation

func (g *Handle) NewSubscriptionHandler(kubeconfig, apiHost string, loginHandler login.Handler) http.Handler {
	return graphqlws.NewHandler(graphqlws.HandlerConfig{
		SubscriptionManager: subscription.Manager(),
		Authenticate: func(token string) (interface{}, error) {
                            // Auth code, removed for obvious purpose
		},
	})
}

Could you please advise how to handle or fix this issue ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions