You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Ignore anything we receive on the original call.
()
}
}
}
but once it retried, it did not get any response out. Also modified it to accommodate for doing N retries with a X seconds delay in between, but got multiple error while using.
Original:
I have implemented what I think should be a sufficient interceptor for retrying, but now I start thinking if this is even possible from inside the interceptor itself.
Here is the sample code. The basic idea is that on sending the parts I store them for a possible retrying and if I receive response that is not OK or get a transport error, I just re-send the parts. But the problem is that after I re-send the parts, nothing happens - I get no more interceptor events at all and there is nothing happening at all based on the logs.
import Foundation
import GRPC
import NIO
classRetryingInterceptor<Request,Response>:ClientInterceptor<Request,Response>{privateletdelay:Int64privateletmaxRetries:IntprivatevarremainingRetries:IntprivatevarinitialRequestParts:[GRPCClientRequestPart<Request>]=[]init(maxRetries:Int, delay:Int64){self.maxRetries = maxRetries
self.delay = delay
self.remainingRetries = maxRetries
}overridefunc send(_ part:GRPCClientRequestPart<Request>, promise:EventLoopPromise<Void>?, context:ClientInterceptorContext<Request,Response>){
initialRequestParts.append(part)
context.send(part, promise: promise)}overridefunc receive(_ part:GRPCClientResponsePart<Response>, context:ClientInterceptorContext<Request,Response>){
switch part {case.end(let status, _)where !status.isOk && remainingRetries >0:NSLog("TEST Response error, retrying...")
remainingRetries -=1
context.eventLoop.scheduleTask(in:.seconds(delay)){self.retry(context: context)}default:
context.receive(part)}}privatefunc retry(context:ClientInterceptorContext<Request,Response>){
for part in initialRequestParts {
context.send(part, promise:nil)}}overridefunc errorCaught(_ error:anyError, context:ClientInterceptorContext<Request,Response>){
if remainingRetries >0{NSLog("TEST Transport error, retrying...")
remainingRetries -=1
context.eventLoop.scheduleTask(in:.seconds(Int64(delay))){self.retry(context: context)}}else{NSLog("TEST Transport error, no more retries.")
context.errorCaught(error)}}}
The text was updated successfully, but these errors were encountered:
What are you trying to achieve?
The server sometimes returns errors or throttles the requests, so I want to be able to retry requests.
What have you tried so far?
Update:
I also looked into
grpc-swift/Tests/GRPCTests/InterceptorsTests.swift
Lines 225 to 327 in 945f7f7
Original:
I have implemented what I think should be a sufficient interceptor for retrying, but now I start thinking if this is even possible from inside the interceptor itself.
Here is the sample code. The basic idea is that on sending the parts I store them for a possible retrying and if I receive response that is not OK or get a transport error, I just re-send the parts. But the problem is that after I re-send the parts, nothing happens - I get no more interceptor events at all and there is nothing happening at all based on the logs.
The text was updated successfully, but these errors were encountered: