Google Cloud with Node Js running WebSocket returns an error from a failed readiness check

103 views Asked by At

I am working on deploying a WebSocket based app, and everything was working perfectly locally, so I was ready to deploy on the Google Cloud. When I deployed the app for the first time, I was getting favicon errors, I managed to fix that error, but after than I kept getting "Failed to load resource: the server responded with a status of 503 ()", when I reload the page, I get the error "GET https://ID.uc.r.appspot.com/ 503 (Service Unavailable)". When I go to the logs it says, "The request failed because the instance failed the readiness check."

I tried looking online but couldn't really find anything specifically relating to my problem. I added all the code in the server.js file that sets up the server. I recently added the readiness check to try and fix the problem, but that did not fix anything. I do have several functions that run right after this code, none of them have promises, I don't know if that would mess anything up.

const express = require('express');
const http = require('http');
const path = require('path');
const WebSocket = require('ws');

var app = express();

//readiness check
app.get('/_ah/health', (req, res) => {
    res.status(200).send('OK');
});

app.use(express.static(path.join(__dirname, 'public')));
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
app.set('trust proxy', true);

app.get('/', (req, res) => {
    res.sendFile('navigator.html', { root: path.join(__dirname, 'public') });
});

app.get('/style.css', (req, res) => {
    res.sendFile('style.css', { root: path.join(__dirname, 'public') });
});

app.get('/client.js', (req, res) => {
    res.sendFile('client.js', { root: path.join(__dirname, 'scripts') });
});

const server = http.createServer(app);
const sockserver = new WebSocket.Server({ server });

server.listen(port, () => {
    console.log(`Server is running on port ` + port);
});

then I added the following code to my app.yaml file

readiness_check:
  path: "/_ah/health"
  check_interval_sec: 5
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 300

Locally, I can go to the /_ah/health page and see the OK status, but that does not show up when I deploy the app. This is my first experience with both WebSocket and the Google Cloud, so it is very likely that I am missing something essential, however I do not know what that missing piece is. I appreciate any help.

0

There are 0 answers