Skip to content

feat: allow to set a connection manager #383

@linde9821

Description

@linde9821

I have an application that needs to handle multiple requests at the same time. When multiple requests are executed at the same time, the following exception occurs (to reproduce this, make sure there are at least 3 or more requests "at the same time"):

java.lang.IllegalStateException: Connection CLIENT_IP_ADDRESS<->SERVER_IP_ADDRESS is still allocated
	at org.apache.hc.core5.util.Asserts.check(Asserts.java:50)
	at org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager.getConnection(BasicHttpClientConnectionManager.java:306)
	at org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager$1.get(BasicHttpClientConnectionManager.java:235)
	at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.acquireEndpoint(InternalExecRuntime.java:109)
	at org.apache.hc.client5.http.impl.classic.ConnectExec.execute(ConnectExec.java:125)
	at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
	at org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ProtocolExec.java:192)
	at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
	at org.apache.hc.client5.http.impl.cache.CachingExec.callBackend(CachingExec.java:237)
	at org.apache.hc.client5.http.impl.cache.CachingExec.handleCacheMiss(CachingExec.java:445)
	at org.apache.hc.client5.http.impl.cache.CachingExec.execute(CachingExec.java:198)
	at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
	at org.apache.hc.client5.http.impl.classic.HttpRequestRetryExec.execute(HttpRequestRetryExec.java:96)
	at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
	at org.apache.hc.client5.http.impl.classic.RedirectExec.execute(RedirectExec.java:115)
	at org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
	at org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:170)
	at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:106)

It seems to me that the BasicHttpClientConnectionManager is not thread-safe. I was hoping to work around this by creating a new client per request, but this does not solve the problem.

If the threadsafty is the reason why it is not working then one could implement the IHttpManager which is provided by the library in the form of the SpotifyHttpManager. However, it would be much easier if the SpotifyHttpManager.Builder would allow to set a connectionManager, otherwise all the spotify-api related implementation details (which this beautiful library provides) would have to be re-written.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions