How to keep grpc-js client connection open (alive) during inactive times? - grpc

I have a grpc server streaming RPC that communicates with the client. The client throws an error when it does not receive communication from the server. The error is:
Error: 13 INTERNAL: Received RST_STREAM with code 2
at Object.callErrorFromStatus (/app/node_modules/#grpc/grpc-js/build/src/call.js:30:26)
at Object.onReceiveStatus (/app/node_modules/#grpc/grpc-js/build/src/client.js:328:49)
at Object.onReceiveStatus (/app/node_modules/#grpc/grpc-js/build/src/client-interceptors.js:304:181)
at Http2CallStream.outputStatus (/app/node_modules/#grpc/grpc-js/build/src/call-stream.js:116:74)
at Http2CallStream.maybeOutputStatus (/app/node_modules/#grpc/grpc-js/build/src/call-stream.js:155:22)
at Http2CallStream.endCall (/app/node_modules/#grpc/grpc-js/build/src/call-stream.js:141:18)
at ClientHttp2Stream.stream.on (/app/node_modules/#grpc/grpc-js/build/src/call-stream.js:410:22)
at ClientHttp2Stream.emit (events.js:198:13)
at emitCloseNT (internal/streams/destroy.js:68:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
Emitted 'error' event at:
at Object.onReceiveStatus (/app/node_modules/#grpc/grpc-js/build/src/client.js:328:28)
at Object.onReceiveStatus (/app/node_modules/#grpc/grpc-js/build/src/client-interceptors.js:304:181)
[... lines matching original stack trace ...]
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
I have tried searching for solutions and the only "solution" that kept the connection open was to manually ping the client every 10 seconds using setInterval. I read that grpc is supposed to keep the connections open for you and even reconnect if it is lost in this article.
As mentioned above, KeepAlive provides a valuable benefit: periodically checking the health of the connection by sending an HTTP/2 PING to determine whether the connection is still alive.
The way I set up the client is below
var grpc = require('#grpc/grpc-js');
require('dotenv').config({path:'/app/.env'});
var responderProto = grpc.loadPackageDefinition(packageDefinition).responder;
var client = new responderProto.ResponderService(process.env.GRPC_HOST_AND_PORT,
grpc.credentials.createInsecure(),
{
"grpc.http2.max_pings_without_data" : 0,
"grpc.keepalive_time_ms": 10000,
"grpc.keepalive_permit_without_calls" : 1
});
My understanding was that the "grpc.keepalive_time_ms" is supposed to ping the server every x ms
Am I doing something wrong or missing or misunderstanding something essential?

Related

gRPC client can't connect to server Failed parsing HTTP/2, only on my computer

I'm trying to connect to a server from my client using gRPC, but connection always fails only on my pc(macbook pro). My teammate tried with the exact same code, and it works perfectly fine. The following is the error messages from each client and server. We are using protobuf 3, python 3.9. Can anyone give me some hint? Thank You.
Client Error Message
grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "Failed parsing HTTP/2"
debug_error_string = "{"created":"#1626678822.089372000","description":"Error received from peer ipv4:10.113.66.145:9390", "file":"src/core/lib/surface/call.cc", "file_line":1067,"grpc_message":"Failed parsing HTTP/2","grpc_status":14}"
Server Error Message
[07/19 01:29:32 cctv_service]: Session Connected
E0719 01:29:32.744434791 14615 parsing.cc:302] Unknown frame type 71
I0719 01:29:32.744519637 14615 chttp2_transport.cc:812] W:0x7f3364002ae0 SERVER [ipv4:10.25.211.173:50662] state IDLE -> WRITING [CLOSE_FROM_API]
I0719 01:29:32.744554230 14615 chttp2_transport.cc:812] W:0x7f3364002ae0 SERVER [ipv4:10.25.211.173:50662] state WRITING -> WRITING [begin write in current thread]
Updated MacOS 11.4 to 11.5, problem never appeared again.

Activemq 5.14.5 http connector Read timed out

To allow the ActiveMQ client and broker to tunnel over HTTP, I'm following the reference documentation http-and-https-transports-reference and I add in activemq.xml file:
<transportConnector name="http" uri="http://0.0.0.0:8081"/>
Starting activemq broker, and when consuming message, the error log is as follows:
Caused by: java.io.IOException: Failed to perform GET on: http://10.128.64.2:8081 Reason: Read timed out
at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:34) ~[activemq-client-5.14.5.jar!/:5.14.5]
... 2 more
Caused by: java.net.SocketTimeoutException: Read timed out
Any help
Thanks
In the meantime I found the cause for the problem. A default socket timeout of 30 secods for the HTTP client was introduced with the following ticket: https://issues.apache.org/jira/browse/AMQ-6397
This timeout somewhow seems to conflict with the keep alive requests that stays open for arround 30 seconds. I increased the default timeout to 90 seconds and this seems to resolve the problem (see attached version of HttpClientTransport.java).
source: https://jira.apache.org/jira/browse/AMQ-6949

Using a KillSwitch in an akka http streaming request

I'm using Akka's HTTP client to make a connection to an infinitely streaming HTTP endpoint. I am having difficulty getting the client to close the upstream to the HTTP server.
Here's my code (StreamRequest().stream returns a Source[T, Any]. It's generated by Http().outgoingConnectionHttps and then a Flow[HttpResponse, T, NotUsed] to convert HttpResponse to a stream of T):
(killSwitch, tFuture) = StreamRequest()
.stream
.takeWithin(timeToStreamFor)
.take(toPull)
.viaMat(KillSwitches.single)(Keep.right)
.toMat(Sink.seq)(Keep.both)
.run()
Then I have
tFuture.onComplete { _ =>
info(s"Shutting down the connection")
killSwitch.shutdown()
}
When I run the code I see the 'Shutting down the connection' log message but the server tells me that I'm still connected. It disconnects only when the JVM exits.
Any ideas what I'm doing wrong or what I should be doing differently here?
Thanks!
I suspect you should invoke Http().shutdownAllConnectionPools() when tFuture completes. The pool does not close connections because they can be reused by the different stream materialisations, so when the stream completes it does not close the pool. The shut connection you seen in the log can be because the idle timeout has triggered for one of the connections.

Using Flash Media Gateway Application

I got a IP Communications new account having following paramters:
Originating IP Destination IP Protocol Codec Ports
(for example)65.154.35.210 , 202.124.43.256 , SIP , g729 / , 2
Now i want to use it in default application of FMG i.e:
http://download.macromedia.com/pub/labs/flashmedia_gateway/flashmedia_gateway_sample_flashphone.swf
Its showing me connecting ...
Status is not getting update like: "Connection Failed" or "Connection Success".
Please tell me how to use the above information in this app, or please sugets me an app any other app to experience FMG.
Regards
Ankush
If you are opening a socket connection, refer to the documentation and different events which are dispatched by the Socket class. Add event handlers to the following events and update the message box when the corresponding events fire.
close: Dispatched when the server closes the socket connection.
connect: Dispatched when a network connection has been established.
ioError: Dispatched when an input/output error occurs that causes
a send or load operation to fail.
securityError: Dispatched if a call to Socket.connect() attempts to
connect either to a server outside the
caller's security sandbox or to a port
lower than 1024.
socketData: Dispatched when a socket has received data.

Service not available, closing transmission channel. The server response was: 4.4.2 Timeout while waiting for command

I'm trying to send a message and we sometime get this error :
Service not available, closing transmission channel. The server response was: 4.4.2 Timeout while waiting for command.
Anyone know what to do with this? Because it only happens "sometime" and apperently, for no specific reason.
I saw many article saying :
442 The server started to deliver the message but then the connection was broke (Source : http://www.sorkincomputer.net/SMTP%20errors.htm)
This is typically a server side (the SMTP server you're delivering to) error or a network connectivity error. There isn't anything you can do about it via your code, you would need to get the related IT staff involved to figure out why your connection is getting closed or interrupted.

Resources