grpc / grpc/grpc-java

Ability to get callExecutor in ClientInterceptor implementation

Aperta
#7,868 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Java
Stelle
12.1k
Fork
4k
Merge medio
2g 17h
PR unite (30g)
37

Descrizione

Various interceptor implementations need to invoke listener callbacks such as in scenarios:
- returning a [FailingClientCall](https://github.com/grpc/grpc-java/blob/v1.35.0/alts/src/main/java/io/grpc/alts/FailingClientCall.java#L34)
- delaying requests and responses
- retrying requests

However, those listener callbacks maybe called in a wrong thread that its user or the channel provider does not intend to use. I believe many interceptor implementations have been doing this. The callbacks should be running in application thread (executed by callExecutor).

`CallOptions` provides `getExecutor()`, but this may return `null`, and in that case the callExecutor should fallback to the channel executor.

In some cases this would not be a big problem, but not in the case of delay, retry, or there are other interceptors switching application thread/running async tasks involved. The problem could be even more difficult to resolve if an interceptor implementation is to be used as a library for others.

Possible solutions:

- In `ManagedChannelImpl`, we add
```java
if (callOptions.getExecutor() == null) { callOptions.withExecutor(channelExecutor); }
```
But if the interceptor uses a different channel, callOptions.getExecutor() may still be null.

- Add a `getExecutor()` method for `Channel` class. Then Interceptor can call `nextChannel.getExecutor()` as a fallback of `callOptions.getExecutor()`.

Problems to some solutions:
- Executor lifecycle.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start by reading CallOptions.getExecutor(), ClientInterceptor implementations, and the proposed ManagedChannelImpl and Channel entry points. Compare the fallback options for obtaining the callExecutor, including executor lifecycle concerns, and define how listener callbacks from delayed, retried, or failing calls should consistently run on the intended executor.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
grpc, java
Ambito
api
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.