async-http-client icon indicating copy to clipboard operation
async-http-client copied to clipboard

Unix Domain Socket URLs are not idempotent

Open karwa opened this issue 4 years ago • 4 comments

AHC has an interesting quirk with how it supports unix: URLs - if the URL has a baseURL, the path of that base URL is taken as the socket path, and the relative path on top is taken as the path "within" the socket.

Basically it's squishing 2 paths in to the same URL - but not the same URL string, just the URL object. It's just an extremely fragile artefact of Foundation's URL model, and is not idempotent with respect to serialization, the .absoluteURL property, or many of the other modifications people like to make to URLs.

In fact it's so fragile that I'd argue the only way to reliably use this feature is directly in the Request initializer. If that's the case, a new initializer on Request would fulfil that need better (of course, there are also http+unix: URLs if you need to encode the entire request as a URL, and they do not have any of these idempotence issues).

Would it be possible to deprecate and remove the UDS base-path quirk?

Offending code is here - note that the socket path and uri depend on the presence of a base URL.

karwa avatar Feb 27 '21 00:02 karwa

I have no objection to deprecating it, though we can't immediately remove it. Deprecation will put it on a path to removal at some future point though.

@krzyzanowskim added the patch though, so I'd like his input if he's willing to give it.

Lukasa avatar Mar 03 '21 10:03 Lukasa

I don't have a strong opinion. @karwa mind preparing PR with proposed change maybe?

krzyzanowskim avatar Mar 03 '21 10:03 krzyzanowskim

Deprecation without removal is a little difficult, because there's no particular function or public type to annotate.

What I could perhaps do is log some kind of warning when we detect such a URL, saying that the functionality is deprecated and will be removed in a future version, pointing them towards http+unix URLs instead.

The best reason for removal, beside it being so fragile, is that it makes it very hard to move to a new URL type. The latest URL standard doesn't preserve its base URL - you just have a URL, parse a relative string against it, and get a new URL. Idempotence WRT serialisation is crucial, so having state which is not encoded in the string representation would be a huge burden to try to support (for very little gain).

karwa avatar Mar 03 '21 10:03 karwa

@karwa oops. So this is a little gross but we could just log a logger.warning the first time we see one of those URLs?

weissi avatar Mar 03 '21 10:03 weissi