Release job on Heroku randomly stops sending Files over FTP - heroku

I have an app release process that has been working fine for a week or two and has now randomly stopped working.
My npm app is built with Heroku and a release job then runs that FTPs the static files to another host. I use the npm ftp library to do this. This has randomly stopped working with a timeout error:
Error: Timeout while connecting to server
at Timeout._onTimeout (/app/node_modules/ftp/lib/connection.js:304:24)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
the release script is as follows:
const DIST_PATH = `dist/cineworld-planner`;
const filesList = readdirSync(join(process.cwd(), DIST_PATH));
const client = new Client();
function pushFiles() {
const putFile = bindNodeCallback(client.put.bind(client));
from(filesList).pipe(
mergeMap(fileName => {
const localPath = join(process.cwd(), DIST_PATH, fileName);
console.log(`Putting path ${localPath} to remote ${fileName}`);
return putFile(localPath, fileName);
}, 1)
).subscribe({
complete: () => client.end()
});
}
client.on('ready', () => {
console.log(`READY`);
pushFiles();
});
client.on('error', (error: any) => {
const code = error.code || 'NO_CODE';
console.log(`ERROR: ${code}`);
console.log(error);
process.exit(1);
});
client.connect({
user: process.env.FTP_USER,
host: process.env.FTP_HOST,
password: process.env.FTP_PASSWORD
});
I have asked my host if there are any issues but all they have said is that the IP address that my script reported it was running on was not blocked.
I have tested the script from my home PC and it also works fine from there.
This will be a major pain if this has stopped working. I really don't know what else to try.
Any help very gratefully received.

It turns out that for me the fix was as simple as increasing the timeout:
const connectOptions: Options = {
user: process.env.FTP_USER,
host: process.env.FTP_HOST,
password: process.env.FTP_PASSWORD,
connTimeout: 60000,
pasvTimeout: 60000,
};
client.connect(connectOptions);

Related

NuxtJS 3 $fetch refuse to connect to local server

I am new to Nuxt3. I tried to connect my Nuxt3 app to my backend site which is built with Laravel. My frontend URL is http://localhost:3000 and my backend is http://localhost:8000. When I connect to http://localhost:8000/api/names using "useFetch" inside a component, it runs fine. But when I do it inside server/api/names.js using $fetch, it shows a 500 (Internal server error).
This runs fine (sample.vue)
const getNames = async () => {
let { data } = await useFetch('http://localhost:8000/api/names')
console.log(data);
}
This does not
(sample.vue)
const getNames = async () => {
let { data } = await useFetch('/api/names')
console.log(data);
}
(/server/api/names.js)
export default defineEventHandler(async (event) => {
const { data } = await $fetch("http://localhost:8000/api/names");
return { data };
});
Here's the code on my Laravel app inside api.php (http://localhost:8000/api/names)
Route::get('/names', function (){
$users_name = User::all()->pluck('name');
return response()->json(['names' => $users_name]);
});
Here's the error that shows when I go to network tab
message: "terminated"
stack: "<pre><span class=\"stack internal\">at Fetch.onAborted (node:internal/deps/undici/undici:11000:53)</span>\n<span class=\"stack\">at Fetch.emit (node:events:513:28)</span>\n<span class=\"stack internal\">at Fetch.terminate (node:internal/deps/undici/undici:10272:14)</span>\n<span class=\"stack internal\">at Object.onError (node:internal/deps/undici/undici:11095:36)</span>\n<span class=\"stack internal\">at Request.onError (node:internal/deps/undici/undici:6477:31)</span>\n<span class=\"stack internal\">at errorRequest (node:internal/deps/undici/undici:8440:17)</span>\n<span class=\"stack internal\">at Socket.onSocketClose (node:internal/deps/undici/undici:7895:9)</span>\n<span class=\"stack\">at Socket.emit (node:events:513:28)</span>\n<span class=\"stack\">at TCP.<anonymous> (node:net:313:12)</span></pre>"
statusCode: 500
statusMessage: ""
url: "/api/names"
I tried to restart both servers hoping that doing this would fix the issue but the problem still persists. Also searched if it has something to do with CORS but it connects when I call the api inside a component.
I had exactly the same problem yesterday and luckily I found a solution without having to downgrade the version of NodeJS because Nuxt3 does not work well under version 16 of Node.
First use Laragon for your Laravel Backend. Laragon automatically creates Hostname for projects ex: laravelbackend.test if the project folder is called "laravelbackend".
Then on the file (/server/api/names.js) replace localhost:8000/api with laravelbackend.test/api
export default defineEventHandler(async (event) => {
const { data } = await $fetch("http://laravelbackend.test/api/names");
return { data };
});

sveltekit/vite problem with self signed certificate on localhost

In my dev environment I'm using the basicSsl-Plugin for generating a self-signed-certificate. The website works fine under https until the fetch function is trying to delete a user.
my vite.config.js:
plugins: [
basicSsl(),
sveltekit(),
{
name: 'sveltekit-socket-io',
configureServer(server) {
const io = new Server(server.httpServer);
io.on('connection', (socket) => {
const agent = new https.Agent({
rejectUnauthorized: false
});
socket.on('disconnect', () => {
await fetch('https://localhost:5173/api/users', {
method: 'DELETE',
body: JSON.stringify({ id: socket.uid }),
agent: agent
});
});
});
i get the error Error: self-signed certificate and code DEPTH_ZERO_SELF_SIGNED_CERT.
when instead of using the basicSsl-Plugin I try using using mkcert-created self signed certificates I cant even access the website anymore with https because I get the following error in the browser: ERR_SSL_VERSION_OR_CIPHER_MISMATCH.
I added process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; and now it seems to work. I guess it's fine for development purposes, don't use it on production.

Solana ECONNREFUSED error on localhost for the simple airdrop transaction

I launched my local solana environment with 'solana-test-validator' command, I have a simple POST API like this:
app.post('/test', async (_: any, res: any) => {
const connection = new Connection('http://localhost:8899', 'confirmed');
const wallet = Keypair.generate();
const airdropSignature = await connection.requestAirdrop(
wallet.publicKey,
LAMPORTS_PER_SOL
);
await connection.confirmTransaction(airdropSignature);
res.json({ message: 'Ok' });
});
And I'm getting an error "request to http://localhost:8899/ failed, reason: connect ECONNREFUSED".
Meanwhile my CLI works. What am I doing wrong?
MacOs, node version 18.0.6, #solana/web3.js version 1.55.0
I don't know why, but it worked for me after I changed 'localhost' to '127.0.0.1'

Can't make a simple socket.io work ( even though equivalent Websocket code works )

Codes based from https://github.com/fireship-io/socketio-minimal-demo/blob/main/server/index.js
Only Version 1 (Websocket version) below works:
wscat -c "ws://localhost:8282"
Connected (press CTRL+C to quit)
> s
< Roger that! s
> f
< Roger that! f
Version 2 & 3 (socket.io version) returns socket hang-up:
wscat -c "ws://localhost:8282"
error: socket hang up
Version 1: Websocket
// server.js
const WebSocket = require('ws')
const server = new WebSocket.Server({ port: '8282' })
server.on('connection', socket => {
socket.on('message', message => {
console.log(message)
socket.send(`Roger that! ${message}`);
});
});
Version 2: socket.io+http
// server.js
const http = require('http').createServer();
const io = require('socket.io')(http, {
cors: { origin: "*" }
});
io.on('connection', (socket) => {
console.log('a user connected');
socket.on('message', (message) => {
console.log(message);
io.emit('message', `${socket.id.substr(0,2)} said ${message}` );
});
});
http.listen(8282, () => console.log('listening on http://localhost:8282') );
Version 3: socket.io only
// server.js
const options = { /* ... */ };
const io = require("socket.io")(options);
// const io = require("socket.io");
io.on('connection', (socket) => {
console.log('a user connected');
socket.on('message', (message) => {
console.log(message);
// io.emit('message', `${socket.id.substr(0,2)} said ${message}` );
});
});
io.listen(8282);
I run the backend using node server.js
I have also tested the response using Simple Websocket Client extension on chrome I get the same behavior when I test using wscat in the terminal.
Thanks for the tip from Mehmet, I checked the url+params at the dev tools network tab and made it work.
wscat -c "ws://localhost:8282/socket.io/?EIO=4&transport=websocket"
Connected (press CTRL+C to quit)
< 0{"sid":"sSYAv_rKLATxmMEGAAAT","upgrades":[],"pingInterval":25000,"pingTimeout":20000}
< 2
Disconnected (code: 1005, reason: "")
It seems everything should be already working anyway if only I use the socket.io-client js lib to connect (while on html+javascript).
When I used command-line wscat, I did not know that there should be parameters in the url when using socket.io
The fix was simple after I checked the url+params the socket.io client is using to connect to the server (visible at chrome devtools network tab).

Svelte/Sveltekit and socket.io-client not working in dev (works in preview)

I'm trying to make socket.io-client work in a svelte front end app to talk to an existing API server that already uses socket.io. After a number of challenges, I managed to make this work but I can only get this to work with sveltekit's preview and not in dev mode. Wondered if someone with some knowledge of those could explain why or suggest what I need to do to get it connecting in dev?
svelte 3.34.0
sveltekit next-169
socket.io(-client) 4.2.0
basic code as follows, currently within a file $lib/db.js where I define a few stores that are pulled into the layout for general use..
import { io } from "socket.io-client";
import { browser } from '$app/env';
const initSocket = async () => {
console.log('creating socket...');
let socket = io('http://192.168.1.5:4000', { 'connect timeout': 5000 });
socket.on("connect", () => {
// always works in preview...
console.log('socket created with ID:', socket.id);
});
socket.on("connect_error", (error) => {
// permanently fired in dev...
console.error('Failed to connect', error);
});
socket.on("error", (error) => {
console.error('Error on socket', error);
});
socket.on("foo", data => {
// works in preview when server emits a message of type 'foo'..
console.log("FOO:", data);
});
};
if (browser) {
initSocket();
}
// stores setup and exports omitted..
with svelte-kit preview --host I see the socket creation log message with the socket ID and the same can be seen on the api server where it logs the same ID. The socket works and data is received as expected.
with svelte-kit dev --host however, the log message from socket.on("connect").. is never output and I just see an endless stream of error messages in the browser console from the socket.on("connect_error").. call..
Failed to connect Error: xhr poll error
at XHR.onError (transport.js:31)
at Request.<anonymous> (polling-xhr.js:93)
at Request.Emitter.emit (index.js:145)
at Request.onError (polling-xhr.js:242)
at polling-xhr.js:205
Importantly, there is no attempt to actually contact the server at all. The server never receives a connection request and wireshark/tcpdump confirm that no packet is ever transmitted to 192.168.1.5:4000
Obviously having to rebuild and re-run preview mode on each code change makes development pretty painful, does anyone have insight as to what the issue is here or suggestions on how to proceed?
I've had a similar problem, I solved it by adding this code to svelte.config.js:
const config = {
kit: {
vite: {
resolve: {
alias: {
"xmlhttprequest-ssl": "./node_modules/engine.io-client/lib/xmlhttprequest.js",
},
},
},
},
};
The solution was provided by this comment from the vite issues.

Resources