square / retrofit

A type-safe HTTP client for Android and the JVM
https://square.github.io/retrofit/
Apache License 2.0
43.08k stars 7.3k forks source link

Strange issue - retrofit replaces request address #1204

Closed justozz closed 9 years ago

justozz commented 9 years ago

I'm making a call using retrofit 2.0 (using wi-fi). I'm using base url, in example, "http://someapi.com", using annotation @POST("/api/somemethod"), then call using "call.execute()". I've got a timeoutexception and it shows me "can't connect to http://someapi.com/[IPv6 address]" (in example http://someapi.com/2001:db8:1234:0000:0000:0000:0000:0000. why didn't it calls "http://someapi.com/api/somemethod"?

P.S. All works using 3G or LTE connection

prashantwosti commented 9 years ago

@justozz In the same wifi, have you tried calling your api using postman or similar desktop rest clients? What's the result?

justozz commented 9 years ago

Through the postman all works. If I'm not using retrofit (I used Volley in example), all also works through wi-fi

shivendrak commented 9 years ago

I also could reproduce this behaviour. Can anyone help ? If it helps, retrofit 1.9 works well but takes ages to complete the request.

JakeWharton commented 9 years ago

@swankjesse any ideas here? redirect + resolve bug, perhaps?

shivendrak commented 9 years ago

Here is some analysis. I was digging into the source code of retrofit and found the attached case. Not sure if it helps. okhttpbug

shivendrak commented 9 years ago

Hi @JakeWharton

I see this ticket has "needs info" tag. Please mention what data is needed. I might be of help.

swankjesse commented 9 years ago

Your screenshot is not showing a URL. InetSocketAddress is showing you two things: a hostname and an IP address, separated by a slash. Note that there is no http:.

In your original report, you said can't connect to http://someapi.com/[IPv6 address]. My guess is that you mistyped the error, which probably said can't connect to someapi.com/[IPv6 address] without the http:// prefix. In this case its a simple issue of an unreachable host.

JakeWharton commented 9 years ago

Please mention what data is needed.

A reproducible test case.

kotucz commented 9 years ago

We had similar issue in our app (not using Retrofit at that time only OkHttp). The DNS had record for both IPv4 and IPv6. The app would try to connect to the IPv6 address but bug in the WiFi router of the users (pretty common device) resulted in timeout. I think this could be resolved with Happy Eyeballs algorithm in OkHttp https://github.com/square/okhttp/issues/506 . Some applications have this or similar already implemented so the issue may not occur with them

shivendrak commented 9 years ago

Hi Jake,

Please follow the url for sample code that recreates the issue in an IpV6 network.

https://onedrive.live.com/redir?resid=FBE59D57B54C08E8!888&authkey=!AAWLnfo1Z3hpn78&ithint=file%2czip

swankjesse commented 9 years ago

I don't think this is a Retrofit issue. If you'd like to report an issue with OkHttp, please do! As is, I suspect your best bet is to get your users to fix their broken IPv6 networks.

yogurtearl commented 2 years ago

I think it is format of the error message that is causing the confusion and that the /<IP address> is just a red herring. The domain/<IP address> comes from the toString method on InetSocketAddress

See https://github.com/square/okhttp/pull/6886