Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch NODE on heroku - node.js

Please my application is unable to run on heroku, heroku is unable to bind to the host port.
I always get Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
I need help in resolving this issue.
My index.js code is presented below.
import http from 'http';
import app from './app';
import dotenv from 'dotenv';
dotenv.config();
const PORT = process.env.PORT || 3000;
const server = http.createServer(app);
console.log('PORT: ', PORT)
server.listen(PORT,'0.0.0.0', () => {
console.log(`server listening on localhost: ${PORT}`);
});
node: 12.16.1
npm: 6.13.4
I have also tried solutions presented online but all to no avail.

You can try to increase boot timeout on Heroku here to the maximum (120 s for free plans).
I had the same problem but on a Springboot Application. It spent more than 60 s to connect to the database and it couldn't bind in time (< 60 s) to the $PORT.

Related

Ngrok reconnecting (failed to fetch CRL. errors encountered: asn1: structure error: length too large)

I can't run ngrok successfully, I'm using a node.js app with the command
app.listen(3000, () => {
console.log('Listening on port', 3000);
});
but yet everytime I start ngrok using ngrok http 3000, it just show up these error messages
reconnecting (failed to fetch CRL. errors encountered: asn1: structure error: length too large)
reconnecting (jsonHTTP.Lookup: No such host: tunnel.ngrok.com)
reconnecting (resolved tunnel.ngrok.com has no records)
I also got the exact same error.
The problem for me was the internet connection - ngrok requires a stable connection, as soon as I changed the wifi network the problem was solved

SignalR with React through NodeJS proxy

I'm trying to use SignalR on a React application through a NodeJS proxy using the NPM package 'http-proxy-middleware'. However, it appears that the connection is falling to connect. Below is the console log from the react application.
[2022-11-29T23:02:24.022Z] Information: Normalizing '/hubs/Chat' to 'https://localhost:3000/hubs/Chat'.
[2022-11-29T23:02:24.022Z] Debug: Starting connection with transfer format 'Text'.
[2022-11-29T23:02:24.023Z] Debug: Sending negotiation request: https://localhost:3000/hubs/Chat/negotiate?negotiateVersion=1.
[2022-11-29T23:02:24.642Z] Debug: Selecting transport 'WebSockets'.
[2022-11-29T23:02:24.643Z] Trace: (WebSockets transport) Connecting.
WebSocket connection to 'wss://localhost:3000/hubs/Chat?id=DykJoTMv9LiYrtjYHUCQVg' failed:
[2022-11-29T23:06:24.671Z] Information: (WebSockets transport) There was an error with the transport.
[2022-11-29T23:06:24.672Z] Error: Failed to start the transport 'WebSockets': Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.
[2022-11-29T23:06:24.672Z] Debug: Skipping transport 'ServerSentEvents' because it was disabled by the client.
[2022-11-29T23:06:24.672Z] Debug: Skipping transport 'LongPolling' because it was disabled by the client.
[2022-11-29T23:06:24.672Z] Error: Failed to start the connection: Error: Unable to connect to the server with any of the available transports. Error: WebSockets failed: Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled. ServerSentEvents failed: Error: 'ServerSentEvents' is disabled by the client. LongPolling failed: Error: 'LongPolling' is disabled by the client.
Error establishing the connection: Error: Unable to connect to the server with any of the available transports. Error: WebSockets failed: Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled. ServerSentEvents failed: Error: 'ServerSentEvents' is disabled by the client. LongPolling failed: Error: 'LongPolling' is disabled by the client.
at HttpConnection._createTransport (HttpConnection.ts:407:1)
at async HttpConnection._startInternal (HttpConnection.ts:283:1)
at async HttpConnection.start (HttpConnection.ts:137:1)
at async HubConnection._startInternal (HubConnection.ts:207:1)
at async HubConnection._startWithStateTransitions (HubConnection.ts:181:1)
If I connect directly to the .NET application, which is running the server-side part of SignalR, it works fine. So it's not a problem with that.
This is the code snippet from the React App which performs the connection.
this.hubConnection = new HubConnectionBuilder()
.withUrl("/hubs/chat",{
transport: HttpTransportType.WebSockets,
logger: LogLevel.Trace
})
.withAutomaticReconnect()
.build();
this.hubConnection.start().catch(error => console.log("Error establishing the connection: ", error));
The proxy is running in NodeJS through nodemon. Below is the code.
const PORT = 8000;
const express = require('express');
const https = require('https');
const fs = require('fs')
const {createProxyMiddleware} = require('http-proxy-middleware');
const app = express();
require('dotenv').config({ path: `.env.${process.env.NODE_ENV.trim()}` });
const httpsOptions = {
key: fs.readFileSync('./certs/cert.key'),
cert: fs.readFileSync('./certs/cert.pem')
}
app.use('/hubs/chat', createProxyMiddleware({
target: process.env.REACT_APP_APISERVICEURL,
changeOrigin: false ,
secure: false,
ws: true,
logger: console
}));
var secure = https.createServer(httpsOptions, app);
secure.listen(8000, () => console.log(`Server is running on port ${PORT}`));
The proxy does work for all other API calls to the .NET Application. The React application has the proxy attribute set in the package.json. The proxy then re-writes the URL and adds an API Token header to send to the API. Hence the use of http-proxy-middleware.
I have tried the below as well, but it still produces the same result.
const signlrRProxy = createProxyMiddleware({
target: process.env.REACT_APP_APISERVICEURL,
changeOrigin: false ,
secure: false,
ws: true,
logger: console
});
app.use('/hubs/chat', signlrRProxy);
var secure = https.createServer(httpsOptions, app);
secure.listen(8000, () => console.log(`Server is running on port ${PORT}`));
secure.on('upgrade', signlrRProxy.upgrade);
I am using the latest package versions to everything.

in heroku nodemon app crash when i am trying to run the server.heroku logs --tail this error showing node/internalmodule/cjsloader936

GITHUB LINK - https://github.com/sc43412/ecomerce-api.git
enter image description here demon] app crashed - waiting for file changes before starting...
2022-03-11T18:52:20.928289+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch.Stopping process with SIGKILLError: Cannot find module '../models/Product'

heroku error Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

I made a scraper with puppeteer and I didn't specified any port for serving it. it just runs and scrape data and exits with process.exit() command.
I deployed it to heroku with cli but after running it throw error:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch.
Stopping process with SIGKILL
Process exited with status 137
whats wrong?
Looks like you have a Web Dyno so the app must bind to $PORT.
You can instead define a worker (in the Procfile) if you do not need incoming HTTP requests.

Express/HTTP listen EADDRINUSE for every port?

This is quite weird i tried at least 30 ports on a CentOS 7 server for the express application and i keep getting:
Uncaught Exception: listen EADDRINUSE :::1238
[ERROR] Stack Trace: Error: listen EADDRINUSE :::1238
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at Server._listen2 (net.js:1253:14)
I tried various different ports and i am pretty sure that nothing is using these ports but i keep getting this error.
Here is my express code:
import http from 'http';
import express from "express";
import compression from 'compression';
import SocketIO from "socket.io";
let App = express();
let HTTPServer = http.Server(App);
let Socket = new SocketIO(HTTPServer);
App.use(compression({}));
HTTPServer.listen(1238, function() {
console.log("Listening..");
});
I checked firewall is off, nothing should block the application. I have one more application runnig on port 8080 just fine. And i just can't get this one working. Any thoughts?
Maybe your process doesn't stop while you are stopping your program in those ports.
try to run these commands in your terminal.
lsof -i:<your port number>
If you got a table then it means your process is not killed, copy that PID from that table and run this command
kill -9 <PID>
this will kill the process running on that port, after this, you can use this port for your program.
I have tested these commands in ubuntu, I don't know about CentOS, but both are Linux so you can try this.

Resources