Ensure proxying to Unix sockets constructs separate HTTP clients #415
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I started to experiment with serving things via Unix sockets (#337), but when I have two separate proxied services, I could only reach one via Jupyterhub; whichever one I used first would also get the requests meant for the other. This change fixes that.
This seems to be because Tornado's HTTP client objects are singletons by default - the docs say:
I think this bug would also affect proxying to a mixture of Unix sockets and TCP sockets, though I haven't tried. If you access something backed by a Unix socket first, that will get any later requests for other proxies; if you use a TCP socket first, anything on a Unix socket will be inaccessible. This should all be fixed by this change - TCP sockets will keep using the singleton HTTP client, and Unix sockets will get their own client each time.
I considered caching the HTTP client objects for Unix sockets in some other way, but it's extra complexity, and I think setting up a SimpleAsyncHTTPClient is cheap enough that we can just do it each time. 馃