Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

479
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!