How to avoid "resource temporarily unavailable" when reading from net.Conn

1,898 views
Skip to first unread message

Roger Pau Monné

unread,
Sep 3, 2010, 2:58:28 PM9/3/10
to golang-nuts
Hello,

I'm working with net.Conn (tcp4), and I get a lot of "resource
temporarily unavailable" using io.ReadFull, what can I do to avoid
this? Or what should I do when I receive this error?

I would like to set the socket to blocking mode, I think this would
solve the issue.

Thanks, Roger.

Russ Cox

unread,
Sep 3, 2010, 3:08:35 PM9/3/10
to Roger Pau Monné, golang-nuts
> I'm working with net.Conn (tcp4), and I get a lot of "resource
> temporarily unavailable" using io.ReadFull, what can I do to avoid
> this? Or what should I do when I receive this error?

You're not supposed to get that error.
Read is supposed to take care of the
blocking for you.

Can you post a program that demonstrates
the problem, and also say which operating
system and architecture you're using?

Thanks.
Russ

Roger Pau Monné

unread,
Sep 3, 2010, 3:36:18 PM9/3/10
to r...@golang.org, golang-nuts
I'm using Mac OS X 10.6.4 and amd64 version of go (release
2010-08-25). It happens with this program:

http://github.com/royger/wgo (check the Wire.go file)

I will try to make a simpler example tomorrow.

Thanks, Roger.

2010/9/3 Russ Cox <r...@golang.org>:

Roger Pau Monné

unread,
Sep 3, 2010, 3:45:46 PM9/3/10
to r...@golang.org, golang-nuts
I've just pushed a new version, that saves a log of every session with
every peer, create a "logs" folder inside "wgo" folder, and run it. I
see this error in almost every file. Although the program is able to
download a torrent.

2010/9/3 Roger Pau Monné <roy...@gmail.com>:

Roger Pau Monné

unread,
Sep 4, 2010, 3:03:27 AM9/4/10
to r...@golang.org, golang-nuts
Hello,

Sorry that I made you loose your time, I've found the problem, I was
setting SetTimeout wrong, so it always returned because the timeout
was very short. Maybe the error could be clearer, something like a
"read timeout" could be much more useful than this.

Thanks anyway, and sorry again.

Russ Cox

unread,
Sep 4, 2010, 8:18:09 AM9/4/10
to Roger Pau Monné, golang-nuts
> Sorry that I made you loose your time, I've found the problem, I was
> setting SetTimeout wrong, so it always returned because the timeout
> was very short. Maybe the error could be clearer, something like a
> "read timeout" could be much more useful than this.

Sounds like a good idea. I've added
http://code.google.com/p/go/issues/detail?id=1078

Russ

Reply all
Reply to author
Forward
0 new messages