You do need to call the callback on the server to end the call. If I am
understanding correctly that those trace logs are from the test where you
removed that call. In that case they will not be helpful. It would be
helpful to have the logs that show the original error you were experiencing.

On the client side, you do need to pass a function for the callback
parameter, but it doesn't need to do anything.

On Tue, Jan 2, 2024 at 10:47 PM Kyaw Thit Lwin <kyaw.thitlwin...@gmail.com>
wrote:

> Hi guys, I have some confusions about grpc-js client streaming. Sorry for
> the long question.
>
>     I have encountered multiple errors, 13 INTERNAL: Received RST_STREAM
> with code 2 triggered by internal client error: Session closed with error
> code 2 during the load testing. May I know what could trigger this error?
>
>     I have the following grpc server and client implementation,
> referencing from 
> *https://github.com/grpc/grpc-node/blob/master/examples/metadata/server.js
> <https://github.com/grpc/grpc-node/blob/master/examples/metadata/server.js>*.
>
> *Client*
> function clientStreamingWithMetadata(client, message) {
> return new Promise((resolve, reject) => {
> const requestMetadata = new grpc.Metadata();
> requestMetadata.set('timestamp', new Date().toISOString());
> const call = client.clientStreamingEcho(requestMetadata, (error, value) =>
> {
> if (error) {
> console.log(`Received error ${error}`);
> return;
> }
> });
> call.on('status', status => {
> const timestamps = status.metadata.get('timestamp');
> if (timestamps.length == 0) {
> console.error("timestamp expected but doesn't exist in trailer");
> }
> resolve();
> });
> for (let i = 0; i < STREAMING_COUNT; i++) {
> call.write({message});
> }
> call.end();
> });
> }
>
>
> *Server*
> function clientStreamingEcho(call, callback) {
> const incomingTimestamps = call.metadata.get('timestamp');
> if (incomingTimestamps.length > 0) {
> console.log('Timestamp from metadata:');
> for (const [index, value] of incomingTimestamps.entries()) {
> console.log(` ${index}. ${value}`);
> }
> }
>
> let lastReceivedMessage = '';
> call.on('data', value => {
> console.log(`Received request ${JSON.stringify(value)}`);
> lastReceivedMessage = value.message;
> });
> call.on('end', () => {
> console.log("Call end!")
> const outgoingTrailers = new grpc.Metadata();
> outgoingTrailers.set('timestamp', new Date().toISOString());
> callback(null, {message: lastReceivedMessage}, outgoingTrailers);
> });
> }
>
> May I also know that do I really need to listen back to the server
> callback on stream end initiated by client side?
>
> I tried running the code by removing the server callback on stream end
> event and remove the call.on('status') listener on the client side. Then
> the client stream doesn't seem to be ended even after call.end() and keep
> pinging the server. These are the logs from server and client.
>
> *Client*
> D 2024-01-03T04:11:09.279Z | v1.9.13 354656 | subchannel_call | [3]
> write() called with message of length 32
> D 2024-01-03T04:11:09.279Z | v1.9.13 354656 | subchannel_call | [3]
> sending data chunk of length 32
> D 2024-01-03T04:11:09.279Z | v1.9.13 354656 | load_balancing_call | [2]
> halfClose called
> D 2024-01-03T04:11:09.279Z | v1.9.13 354656 | subchannel_call | [3] end()
> called
> D 2024-01-03T04:11:09.279Z | v1.9.13 354656 | subchannel_call | [3]
> calling end() on HTTP/2 stream
> D 2024-01-03T04:11:10.277Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Sending ping with timeout 20000ms
> D 2024-01-03T04:11:10.277Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Received ping response
> D 2024-01-03T04:11:10.277Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Starting keepalive timer for 1000ms
> D 2024-01-03T04:11:11.278Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Sending ping with timeout 20000ms
> D 2024-01-03T04:11:11.278Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Received ping response
> D 2024-01-03T04:11:11.278Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Starting keepalive timer for 1000ms
> D 2024-01-03T04:11:12.279Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Sending ping with timeout 20000ms
> D 2024-01-03T04:11:12.279Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Received ping response
> D 2024-01-03T04:11:12.279Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Starting keepalive timer for 1000ms
> D 2024-01-03T04:11:13.281Z | v1.9.13 354656 | keepalive | (3)
> 127.0.0.1:50052 Sending ping with timeout 20000ms
>
> *Server*
> D 2024-01-03T04:11:09.278Z | v1.9.13 352893 | server_call | Received
> message of length 27
> Received request {"message":"this is examples/metadata"}
> D 2024-01-03T04:11:09.279Z | v1.9.13 352893 | server_call | Received
> message of length 27
> Received request {"message":"this is examples/metadata"}
> D 2024-01-03T04:11:09.279Z | v1.9.13 352893 | server_call | Received
> message of length 27
> Received request {"message":"this is examples/metadata"}
> D 2024-01-03T04:11:09.279Z | v1.9.13 352893 | server_call | Received end
> of stream
> Call end!
> D 2024-01-03T04:11:26.004Z | v1.9.13 352893 | server_call | Request to
> method /grpc.examples.echo.Echo/ClientStreamingEcho stream closed with
> rstCode 8
>
> Thank you so much and appreciated any explanation.
>
> --
> You received this message because you are subscribed to the Google Groups "
> grpc.io" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to grpc-io+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grpc-io/9b6662fe-d368-45de-a454-a0273f0c1c09n%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/9b6662fe-d368-45de-a454-a0273f0c1c09n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CAPK2-4c1vpxXXaBN0GZV0EpVEC81ZJmHr3v%2BmU8N0oDPpnvghA%40mail.gmail.com.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to