deeplay-io / nice-grpc

A TypeScript gRPC library that is nice to you

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

All of my requests are staying on pending state

delhamza opened this issue · comments

Can someone tell me how to solve this issue ?

This issue is not actionable unless you provide more details.

I make requests from my front but the moment when i use streams i can't abort the stream, neither catch the end of it and abort.

It is still not clear. Can you make a reproduction example?

`const useStream = () => {
const [currentStream] = React.useState<AsyncIterable>();

const { logout } = useAuth0();

const handleStream = React.useCallback(async function* (
stream: AsyncIterable
) {
try {
for await (const reply of stream) {
console.log("return from stream", reply);

    yield reply;
    if (reply && Object.keys(reply).length !== 0) {
      break;
    }
  }
} catch (error) {
  console.debug("Cancelling stream due to component unmounting", error);
  logout({
    logoutParams: { returnTo: window.location.origin + "?logout=true" },
  });
}

},
[]);` I'm passing the stream request to this hooks but i can't cancel it, neither catch when it's done

When you call an async generator (async function*), it won't execute its code, it will only create and return an AsyncIterable, which must be iterated for the code to be executed.

Try to use a normal async function instead, and remove the yield reply.

Yes But to handle the stream Like this :
for await (const value of handleStream(stream)) { // get the reply }
I'm forced to return an AsyncGenerator

No, you're not. You can use for await in a regular async function.

Even after updating the code the stream get blocked in a pending after a several requests, do you think it comes from the backend configuration ?

You can use a console client like grpcurl to probe your server methods. If the same situation happens with grpcurl, it would mean that the problem is somewhere on the server.

The server is ok i think that the frontend needs a way to close the stream, the used stream remain on the processlist in the backend, i don't seem to find how to close from the frontend in nice-grpc