nodejs request with proxy socket disconnected before secure TLS connection was established error - node.js

I'm trying to connect to instagram.com through proxy. This worked today on another server, but when I moved to new server, it stopped working. I think that the matter is in some network settings, maybe openssl.
const request = require('request');
request({url: 'https://i.instagram.com', proxy: 'http://username:pass#ip:port'}, (err, res, body)=>{console.log(err)})
Output:
{ Error: Client network socket disconnected before secure TLS connection was established
at TLSSocket.onConnectEnd (_tls_wrap.js:1125:19)
at Object.onceWrapper (events.js:286:20)
at TLSSocket.emit (events.js:203:15)
at TLSSocket.EventEmitter.emit (domain.js:466:23)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 'ECONNRESET',
path: undefined,
host: undefined,
port: 0,
localAddress: undefined }
if you change the proxy port to https, then the error will be as follows:
tunneling socket could not be established, cause=write EPROTO 140260722169664:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332
On the old server it worked with http, not https.
I try to install another version of nodes from 10 up to 16

Related

cant access the webapp running in docker with docusaurus

I have built a docker container with docusaurus server and opened port, but the website is not accessible and throws an error like this. How do I allow all the ip address in the docusaurus server?
yarn run v1.22.19
warning package.json: No license field
$ docusaurus-start
LiveReload server started on port 35729
Docusaurus server started on port 3000
Request failed: Error: connect ECONNREFUSED 127.0.0.1:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect',
address: '127.0.0.1', port: 80 }

Greenlock #v4 don't create ssl sertificate

When i start node js server that are using greenlock i got this message
Listening on 0.0.0.0:80 for ACME challenges, and redirecting to HTTPS
Listening on 0.0.0.0:443 for secure traffic
Ready to Serve:
But 2 minutes later i got error message
Error cert_issue:
connect ENETUNREACH 172.31.240.54:80
code: ENETUNREACH
Error: connect ENETUNREACH 172.31.240.54:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
I use virtual server and domen that i buy on GoDaddy

Firebase Functions deploying Not Working, Rejected with [ Server Error. Client network socket disconnected ]

I am trying to deploy my firebase functions but it's giving me an error.
⚠ functions: Upload Error: Server Error. Client network socket disconnected before secure TLS connection was established
Error: Server Error. Client network socket disconnected before secure TLS connection was established
Firebase Debug Log
[warn] ⚠ functions: Upload Error: Server Error. Client network socket disconnected before secure TLS connection was established
[debug] [2020-04-04T17:59:21.405Z] Error: Client network socket disconnected before secure TLS connection was established
at connResetException (internal/errors.js:570:14)
at TLSSocket.onConnectEnd (_tls_wrap.js:1361:19)
at Object.onceWrapper (events.js:299:28)
at TLSSocket.emit (events.js:215:7)
at TLSSocket.EventEmitter.emit (domain.js:476:20)
at endReadableNT (_stream_readable.js:1183:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
[error]
[error] Error: Server Error. Client network socket disconnected before secure TLS connection was established
This problem often happens due to slow internet connection. Please check your Internet connection.

Express server errors with external IP, works fine otherwise

I have an Express server - very small at the moment, this is my whole code:
const express = require('express');
const app = express();
const port = 8080
app.get('/', function(req, res) {
res.send('Hey!')
})
app.listen(port, 'my.ip.address')
It works just fine when my.ip.address is localhost/0.0.0.0/127.0.0.1/192.168.0.28 (my network IP.) But when my external IP is provided, I get this:
events.js:298
throw er; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL: address not available myip:8080
at Server.setupListenHandle [as _listen2] (net.js:1292:21)
at listenInCluster (net.js:1357:12)
at doListen (net.js:1496:7)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1336:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRNOTAVAIL',
errno: -99,
syscall: 'listen',
address: myip,
port: 8080
}
I know that 8080 is correctly forwarded, as another example server (Apache) works just fine, and can be connected to from my external IP.
TLDR:
Just listen to the port and remove the IP address:
app.listen(port)
What's happening:
When you do the following:
app.listen(port, 'my.ip.address')
What you are doing is telling your OS that you want to listen to incoming packet from the port on the network card that owns that IP address.
If the OS cannot find any network card (ethernet, wifi etc.) that has that IP address assigned then your OS will error out saying it cannot find the hardware you want to listen to.
Since your external IP is owned by the external network device of your router your OS cannot find the hardware that owns the IP address.
Altenate solution
You can just listen to the IP address assigned to the network card that is connected to your router:
app.listen(port, 'my.local.ip.address')

ERROR connecting to remote database server(NGINX) via tunneled localhost Node JS

error connecting: Error: Connection lost: The server closed the connection.
at Protocol.end (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\protocol\Protocol.js:109:13)
at Socket.<anonymous> (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\Connection.js:109:28)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
--------------------
at Protocol._enqueue (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\protocol\Protocol.js:141:48)
at Protocol.handshake (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (C:\Users\Tony\Documents\TestServer\node_modules\mysql\lib\Connection.js:130:18)
at Object.<anonymous> (C:\Users\Tony\Documents\TestServer\app.js:13:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
using this code
var express = require('express');
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
port: '8888',
user: 'root',
password: 'xxx',
database: 'shop'
});
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('connected as id ' + connection.threadId);
});
server is BITNAMI using google cloud
localhost is on windows, i can connect to the phpmyadmin through the browser but the script does not work. Thank you
Hi Bitnami developer here,
As you mentioned, you can access phpMyAdmin using the 8888 port because you opened a tunnel to access Apache and that application through that port. You would need to open a new tunnel to access MySQL directly because we configure the server to only listen to localhost for security reasons.
The source port of this new tunnel would be a different port (i.e 8989) and the destination would be localhost:3306 (3306 is the MySQL default port). You would need to modify your code to use the 8989 port instead of the 8888 one.
I hope this information helps.
Jota
To find out if the tunnel is really set up you can run.
sudo lsof -i -n | egrep '\<ssh\>'
you should get some lines out of that. If one of them is around these lines :
ssh 11704 root 3u IPv4 47283826 0t0 TCP [localip]:46286->[remoteip]:ssh (ESTABLISHED)
then the connection is on. In this case you should make sure you are connecting your nodejs application to the correct local port. The code above seems correct just make sure that the tunnel is then from port :8888 to the remote database port, maybe :3607 or whatever the port is.
Otherwise, if your tunnel is not set up properly. There are quite a few tutorials out there explaining how to set an ssh tunnel such as this one :
https://support.cloud.engineyard.com/hc/en-us/articles/205408088-Access-Your-Database-Remotely-Through-an-SSH-Tunnel
Make sure that you also use autossh to set up the tunnel. SSH tunnels are unstable and they tend to fall. Autossh will make sure that the connection is brought back up and that is run when the computer boots up.
https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/

Resources