FAQ

Had a minute to check this out, and I don't see any reason for the panic
here. Is this representative of the actual running code?
This is an abstraction of the actual running code. See:
http://play.golang.org/p/vYwxY8Svds


A couple other issues though:

If all articles download before the timeout, your loop will never exit
until the timeout if there were any errors, since an error condition
doesn't send to articleChan

True. In my actual code, I have error channels as well.
If urlsSlice is very long, you may exhausting some other resource. You may
need to limit the number of simultaneous http or dns calls.
Good point -- but I imagine go should be able to handle downloading a few
hundred websites concurrently, right? Most of the time is spent waiting on
the remote servers anyway.

You don't need to check for `resp == nil`. If the error nil, resp will be
usable, and resp.Body is guaranteed to be non-nil.
What if the remote server returns an empty response?


Your forceTimeout could be replaced with time.After (and don't defer
closing the channel when another goroutine is sending on that channel, this
will panic).
True -- thanks -- I need to udpate that.


You are setting client.Timeout. If you have sane timeouts in the transport
too (see DefaultTransport), you may not need the extra timeout logic at
all, since the client will cancel the request anyway.
In the application, we have various types of timeouts. There are actually
two timeouts -- an http timeout and a loop timeout -- but I simplified and
used one in the code.

In your actual code, is it possible that you have clients stuck sending
to articleChan? That would leave their respective response bodies open,
since it doesn't hit the defer.
It could -- if main execution continues as the loop timeout is hit.
Wouldn't it hit defer when the goroutine returns, even if main execution
has moved on?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 15 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 19, '15 at 4:38p
activeJan 21, '15 at 3:59p
posts15
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase