AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
222 stars 20 forks source link

"Cancelled on client" error in gRPC Client streaming RPC scenario #264

Closed PrasadJayakumar closed 3 months ago

PrasadJayakumar commented 3 months ago

Followed the steps detailed in https://httpyac.github.io/guide/request.html?#client-streaming-rpc

But, getting "Cancelled on client" error in gRPC Client streaming RPC scenario. Am I missing something?

Thank you for sharing the helpful tool.

GRPC /BasicService/CalculateAverage
{
  "value": 10
}

{{@streaming
  async function writeStream(){
    await sleep(1000);
    await $requestClient.send({
      value: 20,
    });
    await sleep(1000);
    await $requestClient.send({
      value: 30
    });
  }
  exports.waitPromise = writeStream();
}}
syntax = "proto3";

package grpc_basics;

service BasicService { 
 // Client streaming RPC: CalculateAverage
 rpc CalculateAverage (stream DataPoint) returns (AverageResponse);
}

message DataPoint {
  double value = 1;
}

message AverageResponse {
  double average = 1; 
}

Code behind the service is provided below.

  calculateAverage(call, callback) {
    // Simulating client streaming by calculating the average of received data points
    let totalSum = 0;
    let count = 0;

    call.on("data", (dataPoint) => {
      console.log("data", dataPoint);
      totalSum += dataPoint.value;
      count++;
    });

    call.on("end", () => {
      const average = count > 0 ? totalSum / count : 0;
      const response = { average: average };
      console.log("end", response);
      callback(null, response);
    });
  }
tcinagaki commented 3 months ago

Hello. Same problem for me. Maybe the reason is that if the StreamingScript terminates while the server is processing, the cancel method is executed. (If the Sleep in the StreamingScript is made longer, the Response is returned normally, but it requires more Sleep than necessary.) It would be great if an option could be implemented to not execute the cancel method even if it is available.

This problem does not occur in version 6.8.1

[6.8.2] (2023-10-23) use grpc Stream cancel method if available

I like this great tool. Thank you.

PrasadJayakumar commented 3 months ago

Hello. Same problem for me. Maybe the reason is that if the StreamingScript terminates while the server is processing, the cancel method is executed. (If the Sleep in the StreamingScript is made longer, the Response is returned normally, but it requires more Sleep than necessary.) It would be great if an option could be implemented to not execute the cancel method even if it is available.

This problem does not occur in version 6.8.1

[6.8.2] (2023-10-23) use grpc Stream cancel method if available

I like this great tool. Thank you.

Thank You.

Yes, Version 6.8.1 is working well.

AnWeber commented 3 months ago

I would just like to briefly point out that v6.8.1 has a memory leak in the streams. You may need to restart the extension host or the entire IDE from time to time if you notice it in the performance. Unfortunately when the streaming went through successfully I decided to call the cancel method instead of the .end(). Almost right. I have fixed it and will be delivered with next release. Tested with ClientStreaming on Postman Echo, but should be identical to your use case. Unfortunately I don't use grpc anymore.