Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

481
Visualizações
Cancel grpc call from client on server streaming

I am using nodejs grpc server streaming to deliver realtime data from server to the clients. As the clients want to listen to the data, they should call a server function which returns a server stream. Then if the client want to end the listening I guess it should call the end method on the call object. But unfortunately I couldn't find any clue on the documentation about how to do this. I have tried call.end and call.destroy and call.cancel but end and destroy did nothing and cancel throws the following error. The sample client side code is as following:

function getData(token, userId) {
    const data =  {
        token,
        userId
    }
    let call = DataService.getData(data)
    call.on('data', res => {
        console.log(res)
    })
    call.on('status', console.log);
    call.on('error', console.log);
    setTimeout(() => {
        
        console.log('destroy')

        call.cancel()
    }, 5000)
}

and the error is:

Error: 1 CANCELLED: Cancelled on client
    at Object.callErrorFromStatus (...grpc\node_modules\@grpc\grpc-js\build\src\call.js:31:26)
    at Object.onReceiveStatus (...grpc\node_modules\@grpc\grpc-js\build\src\client.js:330:49)
    at Object.onReceiveStatus (...grpc\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:299:181)
    at ...grpc\node_modules\@grpc\grpc-js\build\src\call-stream.js:145:78
    at processTicksAndRejections (internal/process/task_queues.js:75:11) {
  code: 1,
  details: 'Cancelled on client',
  metadata: Metadata { internalRepr: Map(0) {}, options: {} }
}
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda