0

My Socketio client does not seem to be able to connect to my Netty-Socketio server on google cloud app engine.

I have a node.js server with React.js client, for websockets I'm working with Socketio. Since Socketio is written for JavaScript originally, we use the Netty-Socketio library to adapt it to the node.js server. The application works smoothly locally, however, now I need to deploy the project to Google Cloud App Engine. Up until the websocket connection is established, the application works fine (with REST API) but then the client does not seem to be able to connect to the port where Socketio runs (9092). I know that the websocket server starts on google cloud because of this log output, which is identical to when I run it locally:

2023-05-15 13:45:47 default[v2]  2023-05-15 13:45:47.524  INFO 1 --- [           main] c.c.socketio.SocketIOServer: Session store / pubsub factory used: MemoryStoreFactory     (local session store only)
2023-05-15 13:45:47 default[v2]  2023-05-15 13:45:47.844  INFO 1 --- [ntLoopGroup-2-1] c.c.socketio.SocketIOServer: SocketIO server started at port: 9092
2023-05-15 13:45:53 default[v2]  2023-05-15 13:45:53.095  INFO 1 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]: Initializing Spring DispatcherServlet 'dispatcherServlet'

The error I get is a CORS Request Denied, Status code (null), but my collegue just gets a timeout error on his computer (same GAE deployment), so I'm not sure if CORS is actually the problem, especially since it does take a long time for that error to be displayed and I've tried modifying the cors files to no avail. Our server runs on port 8080 and all REST requests work fine on that. Websockets run on port 9092. Using the same port did not work (404 error).

Please note that netty-socketio only supports version 1.0+ so I'm using socket.io-client 1.7.4 which is not the latest version.

What I've tried to fix this:

  1. modified the environment to flex

my app.yaml file:

truntime: java
env: flex
automatic_scaling:
  max_num_instances: 1

runtime_config:
  operating_system: "ubuntu22"
  runtime_version: "17"

network:
  session_affinity: true
  forwarded_ports:
      - 9092
  instance_tag: websocket

& made a new version on GAE:

version 2 of GAE instance

  1. Change allowed origin settings. Inspired by the socketio documentation (which is for JavaScript and therefore not directly applicable) and this github issue I've modified my origins and allowed headers for the socket server instantiation:

in application.java:

public SocketIOServer socketIOServer() {         
    Configuration config = new Configuration();
    config.setHostname(host);
    config.setPort(port);
    config.setOrigin("*");        
    config.setAllowHeaders("*");        
    return new SocketIOServer(config);
}

Which did not help.(Note that I am not using credentials or cookies, this is a pretty simple application)

  1. Modified CORS settings for the bucket of the server on google cloud to this:
cors:
    - maxAgeSeconds: 3600
method:
    - GET
    - POST
origin:
    - '*'
responseHeader:
    - '*'

which did not make a difference

  1. session affinity & firewall: Because of this stackoverflow thread I changed the session affinity and firewall settings, although I am pretty certain the firewall already allowed traffick on the 9092 port.

    gcloud compute firewall-rules create default-allow-websockets \      --allow tcp:9092 \      --target-tags websocket \      --description "Allow websocket traffic on port 9092"`

Also did not produce any results.

I still get the same error, everything still doesn't work. Now I'm at the end of my wits. I would appreciate any help, let me know if you need any additional info.

alea
  • 980
  • 1
  • 13
  • 18
a1ps
  • 1

0 Answers0