[refactor] Revise HttpClient creation and caching.#6503
Conversation
|
Thnx! I wonder why I added username/wordt to the record as this should be request based. It was probably to late :-) see more valid points, I will address these. |
…n as attribute is allowed in spec.
…place `invalidateAll` with `reset`, modify JMX registration logic, and enhance cache shutdown handling.
…port for exist specific attributes.
…port for exist specific attributes.
0d62086 to
111c044
Compare
111c044 to
2a78746
Compare
|
[This response was prompted by Joe, drafted by Claude Code, and reviewed by Joe.] Re-reviewing... The approach to caching and reusing the client (plus the JMX visibility) is a real improvement over building and tearing down a client per request. A few things stood out on a close read, grouped by severity. Line numbers are approximate. Blocking — correctness1. Evicted/expired clients are never closed (thread + connection leak). 2. Default HTTP version changed from negotiated HTTP/2 to pinned HTTP/1.1. Should fix — contract / behavior3. 4. Lifecycle & integration5. 6. The JMX bean and the cache lifecycle sit outside eXist's management/lifecycle layer. 7. Minor8. Shared-client cache key — worth a guard/comment. Excluding credentials from the key is correct today because auth is applied per- 9. 10. Small cleanups. The leak (1) and the version default (2) are the two I'd suggest be resolved before merge. |
| * a human-readable summary of the currently cached {@link java.net.http.HttpClient} | ||
| * instances and their configuration.</p> | ||
| */ | ||
| public interface HttpClientCacheMXBean { |
There was a problem hiding this comment.
Claude:
- The JMX bean and the cache lifecycle sit outside eXist's management/lifecycle layer. HttpClientCacheMonitor.register() registers directly on ManagementFactory.getPlatformMBeanServer() with a fixed, non-instance-scoped ObjectName, and HttpClientFactory wires cleanup through a JVM Runtime shutdown hook over a JVM-global static cache. eXist already centralizes MBean registration and teardown in org.exist.management.Agent / AgentFactory (per-instance naming, unregistered in closeDBInstance). As written, in a multi-instance or embedded/test JVM (BrokerPool started and stopped repeatedly) the MBean and cache outlive the database instance, the second register() is a silent no-op pointing at a now-dead cache, and clients are only closed at JVM exit rather than on database shutdown. Registering through the Agent and tying reset() to the module/BrokerPool shutdown path would make this behave like the rest of eXist's JMX and free resources on restart.
Revise HttpClient creation and caching.
follow up for #6482
ToDo