gofeed icon indicating copy to clipboard operation
gofeed copied to clipboard

ParseURL should have reasonable timeout

Open cjacques1 opened this issue 7 years ago • 1 comments

Expected behavior

If the connection to the given url is hanging, the httpClient should timeout. Ideally the desired timeout could be an argument with a reasonable default

Actual behavior

the connection hangs

Steps to reproduce the behavior

find a url with really slow network and try parsing it.

Note: Please include any links to problem feeds, or the feed content itself! the link that hung for me was http://rss.shanghaidaily.com/Portal/mainSite/Handler.ashx?i=7

the function that's hanging for me is ParseURL in parser.go

cjacques1 avatar Nov 02 '17 16:11 cjacques1

set your desired timeout on the parser's client:

fp := gofeed.NewParser()
fp.Client = &http.Client{ Timeout: time.Second*10 } 
feed, _ := fp.ParseURL("http://feeds.twit.tv/twit.xml")
fmt.Println(feed.Title)

peteretelej avatar Jan 05 '18 06:01 peteretelej