Cache evection of HTTP Client lead to not closed HttpClients
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 41
- Fork
- 33
- Merge medio
- 18h 34m
- PR unite (30g)
- 19
Descrizione
Describe the Bug
The current implementation of caching and evicting an HTTP Client lead to not closed HttpClients.
Technically the HttpClients are CloseableHttpClient and should / need(specifically for pooled connections) to be closed after usage.
(See also this discussion)
In the current code-base, when a HttpClient with a PoolingHttpClientConnectionManager is created, it's not cleaned up properly on eviction.
The following workaround does not work in all cases:
cache = Caffeine.newBuilder().expireAfterAccess(duration, unit).ticker(ticker).evictionListener((key, value, cause) -> {
if (value instanceof CloseableHttpClient closeableHttpClient) {
try {
closeableHttpClient.close();
} catch (final Exception e) {
log.warn("Failed to close HttpClient. Ignoring the exception and continue.", e);
}
}
}).build();
There are two basic scenarios:
- The client was created and is no longer in use and the eviction time triggers the cleanup. ✅
- The client was created and in still in use (long running operation, async operation, ...) and the eviction time triggers the cleanup. Then the
evictionListenerwould kill the connection underneath. ❌
Steps to Reproduce
Code review.
Expected Behavior
Proper closing of HttpClients.
Screenshots
No response
Used Versions
Current state in main.
Code Examples
// Your code here
Stack Trace
No response
Log File
Log file
...Affected Development Phase
Development
Impact
No Impact
Timeline
No response
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con DefaultApacheHttpClient5Cache.java nella costruzione della cache collegata e rivedi la discussione nell'issue 755. Traccia come vengono creati, memorizzati nella cache, rimossi e utilizzati i CloseableHttpClients in pool durante operazioni di lunga durata o asincrone; il lavoro è completato quando i client rimossi vengono chiusi senza interrompere i client ancora in uso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- networking
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 32/100