Autoscale deployment stops at Promote but no errors

I have a Python app that runs as expected in Dev. It is setup to deploy to autoscale, but when I do so it stops at promote.

The only feedback I get is:
error: The deployment failed to initialize due to a configuration or code error. Check the logs tab for more information. For additional support, please post on https://ask.replit.com/c/help/13 and a staff member will take a look.

The logs don’t provide any errors.

Any ideas on the issue? Could it be prepared to the port?
I have:

[[ports]]
localPort = 3003
externalPort = 80

Thanks

Hi @BenWisbey , welcome to the forums!
Could you share the deployment logs?
Thanks!

I only get two lines in the logs when the deployment fails. They are:
starting up user application
forwarding local port 3003 to external port 1104

Could you send the link to your repl?

Hi @BenWisbey, we would have to see the Repl contents to know for sure but most often when this happens it is because the application is configured to listen on port 3003, but the Repl never actually starts up on that port. Either it chooses to listen on a different port or it doesn’t listen on a port at all. I would recommend deleting the ports section in your .replit file entirely, then rerun the Repl from the Workspace to repopulate the ports section with the correct values.

1 Like

Hi,
I am facing the same issue. Fail to Promote
Below are the only logs i get:

starting up user application
forwarding local port 3000 to external port 1104
Server is running on port 3000

I have read that it might be due to the cache, but no clue how to clear the cache

Here is my replit file

run = "node server.js"
# run = "python -m http.server"

hidden = ["vite.config.js", ".config"]
modules = ["nodejs-18:v11-20230920-bd784b9", "web:v2-20230623-0b7a606"]

[nix]
channel = "stable-22_11"

[deployment]
deploymentTarget = "cloudrun"
build = ["npm", "run", "build"]
run = ["sh", "-c", "node server.js"]


[[ports]]
localPort = 3000
externalPort = 80

[[ports]]
localPort = 8000
externalPort = 8000

Try removing this bit from the file and try again.

Removed it but still failing to Promote.
still same logs

starting up user application
forwarding local port 3000 to external port 1104
Server is running on port 3000

Could you send the link to your repl?

My replit is in private, I am not comfortable sharing it here on a public forum.

The only thing I changed was to add a maintenance middleware that redirect to index.html when enabled. Below is an extract of my “server.js”

const express = require("express");
const mysql = require("mysql2"); // Change to mysql2
const body_parser = require("body-parser");
const session = require("express-session");
const fs = require("fs");

const app = express();

// Function to check if maintenance mode is enabled
const isMaintenanceMode = () => {
  // Implement your logic to check maintenance mode status
  // For example, you can use an environment variable or a configuration setting
  return true; // Set to true to enable maintenance mode
};

// Maintenance middleware
const maintenanceMiddleware = (req, res, next) => {
  if (isMaintenanceMode() && !req.url.startsWith("/join-list")) {
    res.status(503).sendFile(__dirname + "/index.html");
  } else {
    next(); // Continue to the next middleware
  }
};

app.use(body_parser.urlencoded({ extended: false }));
app.use(body_parser.json());
app.use(express.static("public"));

app.set("view engine", "ejs");

// Apply maintenance middleware here
app.use(maintenanceMiddleware);

// Endpoint to handle form submissions
app.post("/join-list", (req, res) => {
  const { email } = req.body;

  if (!email) {
    return res.status(400).send("Email is required");
  }

  // Save the email to a file (append to a text file)
  fs.appendFile("emails.txt", `${email}\n`, (err) => {
    if (err) {
      console.error("Error saving email:", err);
      return res.status(500).send("Failed to save email");
    }
    console.log("Email saved successfully:", email);
    res.status(200).send("Email added to the waiting list");
  });
});

// Database connection middleware
const connectToDatabase = (req, res, next) => {
  if (!isMaintenanceMode() || req.url.startsWith("/join-list")) {
    // Only establish database connection when not in maintenance mode
    req.pool = mysql.createPool({
      connectionLimit: 10,
      host: process.env["HOST"],
      database: process.env["DATABASE"],
      user: process.env["USER"],
      password: process.env["PASSWORD"],
    });
  }
  next();
};

// Apply database connection middleware to relevant routes
app.use(connectToDatabase);

Could you try adding this to the very bottom of the file?

app.listen(3000);

i already have this at the bottom of the file. Still doesn’t promote

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
1 Like

Can you send screenshots of the Networking tab?

image

1 Like

@nicolasguillon0 As a Core customer, you are welcome to create a private ticket with Support:
https://replit.com/help

That way, you can share your private Repl with us since you’re uncomfortable sharing with a public forum. There are some good recommendations in this thread, but Support can take a look as the “failed to promote” issues can vary on a case-by-case basis.

As an aside, I’d also try increasing your machine configuration if this is Autoscale. Depending on your Repl, you might need to lend it a bit more CPU/RAM so it doesn’t fail/timeout.

3 Likes