Upgrading WebSocket for the first time takes a long time with express + http-proxy-middleware - node.js

I have a Graphql server with subscriptions enabled, when accessed directly from my client it works great. Now what I need to do is reroute the connection through my backend (an express server).
I have the following configuration on my server:
app.use(
"/graphql",
createProxyMiddleware({
target: `http://${GQL_URL}`,
changeOrigin: true,
ws: true,
})
);
This eventually works, however, the first connection when the server starts-up, which I can see in my console the message [HPM] Upgrading to WebSocket takes over five minute to complete.
By the time it manages to upgrade the connection, the client has already disconnected and retried multiple times and I get "instantly" all the stacked pending retries:
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
After that, the connections to the server work properly.
In principle this is not a major problem, as when I deploy, the application will not work for a few minutes and then start working, is not ideal but not all bad.
However, the major problem is when I am developing. Whenever I make any change to the servers code and it reloads I have to wait those few minutes to properly checkout if my application is working.
How can I fix this issue? Am I missing something?

Related

Security handshake failed: {"description":"Handshake read failed"}

What version of gRPC and what language are you using?
#grpc/grpc-js - 1.5.10
What operating system (Linux, Windows,...) and version?
server running in a docker container on azure cloud
What did you do?
I have created a grpc server with SSL. It is a test server, where I use self signed certificates for server. The connection between server and client works fine. But I enabled the debug and trace (tcp, http) logs on the server. I keep getting handshake failed error.
I0427 12:07:40.319067700 18 tcp_server_custom.cc:224] SERVER_CONNECT: 0x7f06409cf3a0 accepted connection: ipv4:10.92.0.9:52824
I0427 12:07:40.319239300 18 tcp_custom.cc:353] Creating TCP endpoint 0x7f0640c78430
I0427 12:07:40.319432800 18 tcp_custom.cc:174] TCP:0x7f0640c78430 read_allocation_done: "No Error"
I0427 12:07:40.319503900 18 tcp_custom.cc:191] Initiating read on 0x7f0640c78430: error="No Error"
I0427 12:07:40.331081600 18 tcp_custom.cc:127] TCP:0x7f0640afea60 call_cb 0x7f0641ed57e0 0x7f0640848b90:0x7f0641ed5610
I0427 12:07:40.331206000 18 tcp_custom.cc:131] read: error={"created":"#1651061260.331064200","description":"EOF","file":"../deps/grpc/src/core/lib/iomgr/tcp_uv.cc","file_line":106}
D0427 12:07:40.331327300 18 security_handshaker.cc:176] Security handshake failed: {"created":"#1651061260.331311100","description":"Handshake read failed","file":"../deps/grpc/src/core/lib/security/transport/security_handshaker.cc","file_line":357,"referenced_errors":[{"created":"#1651061260.331064200","description":"EOF","file":"../deps/grpc/src/core/lib/iomgr/tcp_uv.cc","file_line":106}]}
I0427 12:07:40.331412400 18 tcp_custom.cc:287] TCP 0x7f0640afea60 shutdown why={"created":"#1651061260.331311100","description":"Handshake read failed","file":"../deps/grpc/src/core/lib/security/transport/security_handshaker.cc","file_line":357,"referenced_errors":[{"created":"#1651061260.331064200","description":"EOF","file":"../deps/grpc/src/core/lib/iomgr/tcp_uv.cc","file_line":106}]}
D0427 12:07:40.331443800 18 chttp2_server.cc:122] Handshaking failed: {"created":"#1651061260.331311100","description":"Handshake read failed","file":"../deps/grpc/src/core/lib/security/transport/security_handshaker.cc","file_line":357,"referenced_errors":[{"created":"#1651061260.331064200","description":"EOF","file":"../deps/grpc/src/core/lib/iomgr/tcp_uv.cc","file_line":106}]}
### Anything else we should know about your project / environment?
I have an envoy proxy also running for the grpc server to make grpc-web requests.
Node version: node:14-alpine

Passport-azure-ad : authentication failed due to: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 3128

I try to implement Passport-azure-ad OIDCStrategy on my node application.
It is working find in my personal computer but with my corporate laptop (without VPN or proxy configured) I cannot connect and I get that error :
authentication failed due to: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 3128
I don't understand why because I can access by a browser to https://login.microsoftonline.com/ without any issues.
I don't understand what endpoint node try to contact and why the tunnel socket cannot be established.
Any help ?
Thanks

ngrok error Failed to read valid http request: malformed HTTP request

I'm using ngrok building a Secure tunnels to localhost server
On server side I run the command start ngrok
./bin/ngrokd -domain="tunnel.kmic168.com" -httpAddr=":8080"
Display
[07/12/17 17:37:16] [INFO] [registry] [tun] No affinity cache specified
[07/12/17 17:37:16] [INFO] [metrics] Reporting every 30 seconds
[07/12/17 17:37:16] [INFO] Listening for public http connections on [::]:8080
[07/12/17 17:37:16] [INFO] Listening for public https connections on [::]:443
[07/12/17 17:37:16] [INFO] Listening for control and proxy connections on [::]:4443
It seems fine. Then I run the command on client side
./ngrok -subdomain=rbp -config="ngrok.cfg" 80
and the
Tunnel Status: reconnecting .
Alway reconnecting. Then I checkd the server side display these error
[07/12/17 17:40:13] [INFO] [pub:7ac836d4] New connection from
119.130.171.143:25904 [07/12/17 17:40:13] [WARN] [pub:7ac836d4] Failed to read valid http request: malformed HTTP request
"\x16\x03\x01\x00\x9a\x01\x00\x00\x96\x03\x03;Qߓ\xccj\xb7nm\xa0\xe0\x86\x04\u007fH{W5\x10\xb1\xc4\xcc\xed\xe5\xbf\xc9\x00\xa1ĥbq\x00\x00\x1c\xc0/\xc0+\xc00\xc0,\xc0\x13\xc0\t\xc0\x14\xc0"
[07/12/17 17:40:13] [DEBG] [pub:7ac836d4] Closing [07/12/17 17:40:23]
[INFO] [metrics] Reporting:
{"bytesIn.count":0,"bytesOut.count":0,"connMeter.count":0,"connMeter.m1":0,"httpTunnelMeter.count":0,"linux":0,"osx":0,"other":0,"tcpTunnelMeter.count":0,"tunnelMeter.count":0,"tunnelMeter.m1":0,"windows":0}
Here is my cfg file content
server_addr: "tunnel.kmic168.com:8080"
trust_host_root_certs: false
Is there a solution to resolve this error? Thank you very much!
finally I found the solution
https://gist.github.com/lyoshenka/002b7fbd801d0fd21f2f
you have to use the port 4443

HAProxy 1.6 configuration Node.js ssh server child process

I am running a Node.js SSH server that spawns a child process to exec code (using require('child_process').spawn) after successful authentication.
The client server connections works fine on port 22 and connection is kept alive successfully through spawned process.
I am trying to setup up now with HAProxy 1.6, to forward port 22 to a non-privileged port on which the SSH server is listening.
However, when the child process is spawned the server either errors Error: write EPIPE or Error: read ECONNRESET.
This suggests to me there is an issue with prematurely closed stream or connection between the client -> HAProxy -> server?
I am looking at websocket configurations and ssh configurations for HAProxy and various keep alive options. However I cannot get the connection to work.
My configuration:
global
daemon
maxconn 10000
log 127.0.0.1 local0
defaults
log global
option tcplog
option logasap
timeout connect 500s
timeout client 5000s
timeout server 2h
timeout server-fin 5000s
timeout client-fin 5000s
timeout tunnel 1h
option tcpka
frontend sshd
bind *:22
default_backend ssh
timeout client 2h
backend ssh
mode tcp
server ssh2server 127.0.0.1:5000 check port 5000
Any pointers or help would be awesome. Thanks in advance.
EDIT
Runing haproxy in debug mode I have
00000000:sshd.accept(0004)=0005 from [my ip]
00000000:ssh.srvcls[0005:0006]
00000000:ssh.clicls[0005:0006]
00000000:ssh.closed[0005:0006].
On the tcplog
Oct 15 15:15:38 localhost haproxy[16036]: 128.277.13.23:51146 [15/Oct/2016:15:15:38.804] sshd ssh/ssh2server 1/0/+0 +0 -- 1/1/1/1/0 0/0

Socket.io in reconnecting loop when running in Amazon EC2

I am having a problem with socket.io (websocket) when running in EC2. I don't have any http proxy or loadbalancer installed infront of the node instance. Same code works fine when running in local environment but keep reconnecting in EC2. Also even in the EC2 instance xhr-polling works fine.
Following is socket.io debug log output when transport is set to websocket and xhr-polling.
debug - discarding transport
debug - authorized
info - handshake authorized aoiP_6qFnqiqEC3r2-0N
debug - setting request GET /socket.io/1/websocket/aoiP_6qFnqiqEC3r2-0N
debug - set heartbeat interval for client aoiP_6qFnqiqEC3r2-0N
debug - client authorized for
debug - websocket writing 1::
warn - websocket parser error: reserved fields must be empty
info - transport end (undefined)
debug - set close timeout for client NxkBCtJqwOscfHzE0xba
debug - cleared close timeout for client NxkBCtJqwOscfHzE0xba
debug - cleared heartbeat interval for client NxkBCtJqwOscfHzE0xba

Resources