scalaj-http icon indicating copy to clipboard operation
scalaj-http copied to clipboard

Close Socket

Open crockpotveggies opened this issue 9 years ago • 4 comments

Is there a way to close the underlying TCP socket that's been opened by scalaj-http?

For example, with HttpUrlConnection I can do the following: HttpURLConnection.getInputSteam().close().

I'm having issues with a Proxy timing out because, according to them, each socket should be opened for an individual HTTP request (and then closed). I think the socket connection is being cached.

Let me know if I can clarify this further. I might have missed something in the README.

crockpotveggies avatar Feb 04 '16 02:02 crockpotveggies

Okay after reviewing the source code, it does indeed look like there is a close() method being called on this line: https://github.com/scalaj/scalaj-http/blob/master/src/main/scala/scalaj/http/Http.scala#L394

Am I misunderstanding HttpUrlConnection or does close actually sever the underlying socket? Does it get cached anyways?

If it is being closed, then we can start to suspect a problem downstream.

crockpotveggies avatar Feb 04 '16 18:02 crockpotveggies

I think it is probably being cached if the server supports keep-alive. See the sun implementation notes from java6: http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-keepalive.html

Looks like setting "connection: close" in the request header should help although I haven't tested myself.

On Thursday, February 4, 2016, crockpotveggies [email protected] wrote:

Okay after reviewing the source code, it does indeed look like there is a close() method being called on this line: https://github.com/scalaj/scalaj-http/blob/master/src/main/scala/scalaj/http/Http.scala#L394

Am I misunderstanding HttpUrlConnection or does close actually sever the underlying socket? Does it get cached anyways?

If it is being closed, then we can start to suspect a problem downstream.

— Reply to this email directly or view it on GitHub https://github.com/scalaj/scalaj-http/issues/90#issuecomment-179983690.

hoffrocket avatar Feb 04 '16 21:02 hoffrocket

Did that work for you?

hoffrocket avatar Mar 02 '16 03:03 hoffrocket

Hey thanks for following up! Had prioritize something but I'll try connection close again tomorrow and let you know. Thanks for checking in On Tue, Mar 1, 2016 at 7:46 PM Jon Hoffman [email protected] wrote:

Did that work for you?

— Reply to this email directly or view it on GitHub https://github.com/scalaj/scalaj-http/issues/90#issuecomment-191043414.

crockpotveggies avatar Mar 02 '16 04:03 crockpotveggies