Open vminkov opened 8 years ago
We solved the problem by faking that HttpComponents are not on the classpath and then it uses SimpleClientHttpRequestFactory to make each request without pooling the sockets.
Field field = ClientHttpRequestFactorySelector.class.getDeclaredField("HTTP_COMPONENTS_AVAILABLE"); field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, false);
https://github.com/spring-projects/spring-social/blob/master/spring-social-core/src/main/java/org/springframework/social/support/ClientHttpRequestFactorySelector.java#L91
Even though HttpComponentsClientHttpRequestFactory is a DisposableBean, it is not handled by any BeanFactory when created like that and thus it is too late later when GC tries to close the CloseableHttpClient (and the sockets), but has to wait in it's finilize() method on an internal lock (PoolingHttpClientConnectionManager.shutdown()) . This makes GC way too slow to catch up with the socket creation on our production servers for example.
http://stackoverflow.com/questions/4724193/how-can-i-ensure-that-my-httpclient-4-1-does-not-leak-sockets