Failure to get file from s3

91 views
Skip to first unread message

Oliver Castle

unread,
Feb 25, 2013, 1:02:51 PM2/25/13
to go...@googlegroups.com
I have some code which is working on my local dev machine but when I deploy it onto a EC2 Ubuntu instance I get the error  "use of closed network connection"

func GetFile(fileName string) ([]byte, error) {
auth := aws.Auth{configuration.Get("s3Key"), configuration.Get("s3Password")}
s3 := s3.New(auth, aws.EUWest)
bucket := s3.Bucket(configuration.Get("s3Bucket"))
data, err := bucket.Get(configuration.Get("s3Path") + fileName)
if err != nil {
return nil, err
}
return data, nil
}

Any ideas as it has really stumped me? 

Gustavo Niemeyer

unread,
Feb 25, 2013, 1:09:34 PM2/25/13
to go...@googlegroups.com
On Mon, Feb 25, 2013 at 3:02 PM, Oliver Castle
<oliver...@tribeguru.com> wrote:
> I have some code which is working on my local dev machine but when I deploy
> it onto a EC2 Ubuntu instance I get the error "use of closed network
> connection"

The real error is probably getting eaten by a "shut door".

Can you please enable the debug const flag in the s3 package [1] and
try it out so we can see more details of what's going on?

[1] On a side note, this should really be a public variable so that
you don't have to rebuild the package. I'll put that in the pipeline.


gustavo @ http://niemeyer.net

Oliver Castle

unread,
Feb 25, 2013, 1:22:21 PM2/25/13
to go...@googlegroups.com
2013/02/25 18:13:30 Signature payload: "GET\n\n\nMon, 25 Feb 2013 18:13:30 UTC\n/activity-data/data/10.tcx"
2013/02/25 18:13:30 Signature: "################################"
2013/02/25 18:13:30 Running S3 request: &s3.request{method:"GET", bucket:"activity-data", path:"/activity-data/data/10.tcx", signpath:"/activity-data/data/10.tcx", params:url.Values{}, headers:http.Header{"Authorization":[]string{"AWS AKIAINKTNFQOI3FTQJWQ:##################"}, "Date":[]string{"Mon, 25 Feb 2013 18:13:30 UTC"}, "Host":[]string{"s3-eu-west-1.amazonaws.com"}}, baseurl:"https://s3-eu-west-1.amazonaws.com", payload:io.Reader(nil), prepared:true}
2013/02/25 18:13:30 } -> 
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x14 pc=0x808038d]
goroutine 4 [running]:
testing._func_003(0xb74d9fd4, 0xb74d9100, 0xb74d9c3c)
/usr/lib/go/src/pkg/testing/testing.go:268 +0x11f
----- stack segment boundary -----
io/ioutil._func_001(0xb74d9dcc, 0xb74d9100, 0xb74d9fdc)
/usr/lib/go/src/pkg/io/ioutil/ioutil.go:29 +0xc5
----- stack segment boundary -----
bytes.(*Buffer).ReadFrom(0x1897d5a0, 0x0, 0x0, 0x0, 0x0, ...)
/usr/lib/go/src/pkg/bytes/buffer.go:153 +0x1cc
io/ioutil.readAll(0x0, 0x0, 0x200, 0x0, 0x0, ...)
/usr/lib/go/src/pkg/io/ioutil/ioutil.go:32 +0xf2
io/ioutil.ReadAll(0x0, 0x0, 0x0, 0x0)
/usr/lib/go/src/pkg/io/ioutil/ioutil.go:41 +0x3c
launchpad.net/goamz/s3.(*Bucket).Get(0x1897a820, 0x1897a830, 0xb, 0x0, 0x0, ...)
/usr/local/src/go/src/launchpad.net/goamz/s3/s3.go:141 +0xa4
tribeguru/storage/activity.GetFile(0x8209290, 0x6, 0x5, 0xa)
/usr/local/src/go/src/tribeguru/storage/activity/storage.go:13 +0x1d7
tribeguru/storage/activity.GetRemoteTcx(0x8209290, 0x6, 0x0, 0x0)
/usr/local/src/go/src/tribeguru/storage/activity/tcx.go:71 +0x2c
tribeguru/storage/activity.TestRemoteTcx(0x189658c0, 0xe)
/usr/local/src/go/src/tribeguru/storage/activity/lib_test.go:18 +0x3f
testing.tRunner(0x189658c0, 0x83877e4, 0x0)
/usr/lib/go/src/pkg/testing/testing.go:273 +0x71
created by testing.RunTests
/usr/lib/go/src/pkg/testing/testing.go:349 +0x6af
goroutine 1 [chan receive]:
testing.RunTests(0x8048c00, 0x83877d8, 0x7, 0x7, 0x8376201, ...)
/usr/lib/go/src/pkg/testing/testing.go:350 +0x6cf
testing.Main(0x8048c00, 0x83877d8, 0x7, 0x7, 0x838a5f8, ...)
/usr/lib/go/src/pkg/testing/testing.go:285 +0x5d
main.main()
/tmp/go-build209731040/tribeguru/storage/activity/_test/_testmain.go:55 +0x51
goroutine 2 [syscall]:
created by runtime.main
/build/buildd/golang-1.0.2/src/pkg/runtime/proc.c:221

goroutine 5 [syscall]:
syscall.Syscall6()
/build/buildd/golang-1.0.2/src/pkg/syscall/asm_linux_386.s:46 +0x27
syscall.EpollWait(0x6, 0x18872e68, 0xa, 0xa, 0xffffffff, ...)
/usr/lib/go/src/pkg/syscall/zerrors_linux_386.go:1780 +0x7d
net.(*pollster).WaitFD(0x18872e60, 0x18801f60, 0x0, 0x0, 0x0, ...)
/usr/lib/go/src/pkg/net/fd_linux.go:146 +0x12b
net.(*pollServer).Run(0x18801f60, 0x0)
/usr/lib/go/src/pkg/net/fd.go:236 +0xdf
created by net.newPollServer
/usr/lib/go/src/pkg/net/newpollserver.go:35 +0x308
exit status 2
FAIL tribeguru/storage/activity 0.279s

Seems like the reader is returning nil? I have checked and the file exists in the path specified. This is running on an Ubuntu 12.10 EC2 with just the apt-get golang package.



--
You received this message because you are subscribed to a topic in the Google Groups "goamz" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/goamz/XzK9gKzcf9o/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to goamz+un...@googlegroups.com.

Gustavo Niemeyer

unread,
Feb 25, 2013, 2:05:09 PM2/25/13
to go...@googlegroups.com
On Mon, Feb 25, 2013 at 3:22 PM, Oliver Castle
<oliver...@tribeguru.com> wrote:
>> 2013/02/25 18:13:30 Signature payload: "GET\n\n\nMon, 25 Feb 2013 18:13:30
>> UTC\n/activity-data/data/10.tcx"
>> 2013/02/25 18:13:30 Signature: "################################"

Oliver, I really can't tell what is going on in your environment, and
I'd actually appreciate understanding it, but I'm afraid you'll have
to dive down a bit more.

FYI, I can set up a 12.10 machine from the ground up, and get it
running with that exact script:

http://paste.ubuntu.com/5565556/

This is within EC2, and these credentials are real, so you can paste
it in your environment and try it out.


gustavo @ http://niemeyer.net

Oliver Castle

unread,
Feb 25, 2013, 2:29:27 PM2/25/13
to go...@googlegroups.com
I have tried your code and it works fine, it also works fine with my credentials if I use a small text size but as soon as the file size increases it stops working and returns an error (using your code). 

If you try your code with the file attached (text/xml) you will see the error.




gustavo @ http://niemeyer.net

--
You received this message because you are subscribed to the Google Groups "goamz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to goamz+un...@googlegroups.com.
10.tcx

Gustavo Niemeyer

unread,
Feb 25, 2013, 2:34:21 PM2/25/13
to go...@googlegroups.com
Thanks. There's definitely a bug, which I probably introduced in the
latest retry change. Let me fix that.

On Mon, Feb 25, 2013 at 4:29 PM, Oliver Castle
--

gustavo @ http://niemeyer.net

Gustavo Niemeyer

unread,
Feb 25, 2013, 3:05:57 PM2/25/13
to go...@googlegroups.com
Nope.. there's apparently something more involved. The net/http
package itself is sending a TCP RST packet to S3. I'll have to dig
deeper.

Gustavo Niemeyer

unread,
Feb 25, 2013, 4:28:15 PM2/25/13
to go...@googlegroups.com
Okay, so here is the full story: the golang package in Ubuntu comes
from Debian, and there they have added a hand-picked patch from
upstream due to this issue:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=683421

The patch comes from here:

https://codereview.appspot.com/6201044

If you watch closely, though, right after submission there's a comment saying:

This code breaks Client.Get() on non-persistent ("Connection: close")
connections. Response.Body returns error("use of closed network
connection").

Does that sound familiar? :-)

A patch to fix that immediately followed in a different CL:

https://codereview.appspot.com/6211069

That never made it into the Debian package.

As an easy solution, I suggest you pick the package from the PPA:

sudo add-apt-repository ppa:gophers/go
sudo apt-get update
sudo apt-get install golang-stable


gustavo @ http://niemeyer.net
Reply all
Reply to author
Forward
0 new messages