"use of closed network connection" error

7,594 views
Skip to first unread message

Kier Davis

unread,
Oct 2, 2012, 5:10:12 PM10/2/12
to golan...@googlegroups.com
Here's a link to a short code sample that fetches a URL and reads all the data from the response: https://gist.github.com/3823314

However, when run it crashes with the error "use of closed network connection". A quick search shows that this is produced deep in the net package (fd.go). The error suggests that I'm trying to read from the socket after it's closed, but I don't have a Close() call anywhere in my code which means that something's going wrong in the standard libraries (either there's a bug and its closing it at the wrong time, or it's closing it for good reason but not returning a suitable error)

Kier Davis

unread,
Oct 2, 2012, 5:15:00 PM10/2/12
to golan...@googlegroups.com
I should mention that this problem when downloading from this particular site (repo.bukkit.org). Multiple files on this site exhibit this problem, yet I have not seen this  with with any other sites

Kier Davis

unread,
Oct 2, 2012, 5:22:08 PM10/2/12
to golan...@googlegroups.com
Just seen https://groups.google.com/forum/?fromgroups=#!msg/golang-nuts/NPq12f3FErY/6XFe5s81sD4J, could someone point me to the thread in question?


On Tuesday, 2 October 2012 22:10:12 UTC+1, Kier Davis wrote:

Tamás Gulácsi

unread,
Oct 3, 2012, 4:48:55 AM10/3/12
to golan...@googlegroups.com
Maybe the server cleses before sending content-length bytes? What does curl -v say?

Kier Davis

unread,
Oct 3, 2012, 11:14:32 AM10/3/12
to golan...@googlegroups.com
It works without error when using cURL, but here's the output: https://gist.github.com/3827488


On Tuesday, 2 October 2012 22:10:12 UTC+1, Kier Davis wrote:

gmallard

unread,
Oct 3, 2012, 7:49:57 PM10/3/12
to golan...@googlegroups.com
I can not recreate that.  That go code works fine.

Kier Davis

unread,
Oct 4, 2012, 3:21:10 AM10/4/12
to golan...@googlegroups.com
Ah, I'm on go 1.0.2 - maybe it's been fixed in 1.0.3

Dave Cheney

unread,
Dec 2, 2012, 7:44:03 PM12/2/12
to eint...@paperboardinc.com, golan...@googlegroups.com
Hi Folks,

Rather than this slow motion email thread, can I encourage you to
create an issue on the golang issue tracker.

Cheers

Dave

On Mon, Dec 3, 2012 at 10:45 AM, <eint...@paperboardinc.com> wrote:
> Did you find the solution to this problem? I updated to go 1.0.3 but the
> problem still exists.
> --
>
>

Nikolay Georgiev

unread,
Jan 12, 2014, 3:46:10 AM1/12/14
to golan...@googlegroups.com, eint...@paperboardinc.com, meyer...@gmail.com
Hello,

I'm sorry for such a late reply. I was playing with the Grooveshark's developers site and I seem to get the same "use of closed network connection" error.
I get it only for the body. 

To the test file above (https://gist.github.com/4626358) I just added:

if resp.Request != nil {
fmt.Printf("%#v\n", resp.Request)
fmt.Printf("%#v\n", resp.Body)
}

and change the URL like so:


Here is what I get in the response:

--------------------------------------
&http.Response{Status:"200 OK", StatusCode:200, Proto:"HTTP/1.1", ProtoMajor:1, ProtoMinor:1, Header:http.Header{"X-Hostname":[]string{"rhl060", "rhl060"}, "Vary":[]string{"Accept-Encoding"}, "Date":[]string{"Sun, 12 Jan 2014 08:19:52 GMT"}, "Content-Type":[]string{"text/html; charset=UTF-8"}, "Server":[]string{"richhickey"}}, Body:(*http.bodyEOFSignal)(0xf840056d80), ContentLength:-1, TransferEncoding:[]string(nil), Close:true, Trailer:http.Header(nil), Request:(*http.Request)(0xf84007e000)}
--------------------------------------
&http.Request{Method:"GET", URL:(*url.URL)(0xf8400001c0), Proto:"HTTP/1.1", ProtoMajor:1, ProtoMinor:1, Header:http.Header{}, Body:io.ReadCloser(nil), ContentLength:0, TransferEncoding:[]string(nil), Close:false, Host:"developers.grooveshark.com", Form:url.Values(nil), MultipartForm:(*multipart.Form)(nil), Trailer:http.Header(nil), RemoteAddr:"", RequestURI:"", TLS:(*tls.ConnectionState)(nil)}
--------------------------------------
&http.bodyEOFSignal{body:(*http.readFirstCloseBoth)(0xf840056d60), fn:(func())(nil), isClosed:false}
2014/01/12 10:19:51 use of closed network connection
exit status 1

(go version go1.0.2)

On Thursday, 24 January 2013 21:30:26 UTC+2, meyer...@gmail.com wrote:
I've done a bit of investigation on this issue, and I think I've isolated the failure cases.

Info and test code here: https://gist.github.com/4626358

Bug report here: http://code.google.com/p/go/issues/detail?id=4704

I don't have time to look into it any more than that at the moment, but I'll give it a go later on.

Are there still people who can't reproduce this bug?

-Meyer S. Jacobs

Nikolay Georgiev

unread,
Jan 12, 2014, 4:35:19 AM1/12/14
to golan...@googlegroups.com, eint...@paperboardinc.com, meyer...@gmail.com
OK,  I apologize for the noise. I updated to version 1.2 and the problem is gone.
Reply all
Reply to author
Forward
0 new messages