On Monday, January 19, 2015 at 11:38:20 AM UTC-5, akib...@gmail.com wrote:
Hi Everyone,

I hope this isn't a duplicate issue but:

I have a number of goroutines that each download a url. After a certain
cutoff point (a timeout), main code execution moves on, leaving goroutines
that didn't finish basically hanging.

See: http://play.golang.org/p/OlPuERL2kQ
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?

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

If urlsSlice is very long, you may exhausting some other resource. You may
need to limit the number of simultaneous http or dns calls.

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.

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).

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 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.

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


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 15 | next ›
Discussion Overview
groupgolang-nuts @
postedJan 19, '15 at 4:38p
activeJan 21, '15 at 3:59p



site design / logo © 2022 Grokbase