Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8699507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:57:55+00:00 2026-06-13T01:57:55+00:00

I have this test program which will fetch url parallel, but when I increase

  • 0

I have this test program which will fetch url parallel, but when I increase the parallel number to about 1040, I start to get lookup www.httpbin.org: no such host error.

After some Google, I found others say that not close the response will cause the problem, but I do close that with res.Body.Close().

What’s the problem here? thanks very much.

package main

import (
    "fmt"
    "net/http"
    "io/ioutil"
)

func get(url string) ([]byte, error) {

    client := &http.Client{}
    req, _ := http.NewRequest("GET", url, nil)

    res, err := client.Do(req)

    if err != nil {
        fmt.Println(err)
        return nil, err
    } 

    bytes, read_err := ioutil.ReadAll(res.Body)
    res.Body.Close()

    fmt.Println(bytes)

    return bytes, read_err
}

func main() {
    for i := 0; i < 1040; i++ {
        go get(fmt.Sprintf("http://www.httpbin.org/get?a=%d", i))
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:57:57+00:00Added an answer on June 13, 2026 at 1:57 am

    That’s because you may have up to 1040 concurrent calls in your code so you may very well be in a state with 1040 body opened and none yet closed.

    You need to limit the number of goroutines used.

    Here’s one possible solution with a limit to 100 concurrent calls max :

    func getThemAll() {
        nbConcurrentGet := 100
        urls :=  make(chan string, nbConcurrentGet)
        for i := 0; i < nbConcurrentGet; i++ {
            go func (){
                for url := range urls {
                    get(url)
                }
            }()
        }
        for i:=0; i<1040; i++ {
            urls <- fmt.Sprintf("http://www.httpbin.org/get?a=%d", i)
        }
    }
    

    If you call this in the main function of your program, it may stop before all tasks are finished. You can use a sync.WaitGroup to prevent it :

    func main() {
        nbConcurrentGet := 100
        urls :=  make(chan string, nbConcurrentGet)
        var wg sync.WaitGroup
        for i := 0; i < nbConcurrentGet; i++ {
            go func (){
                for url := range urls {
                    get(url)
                    wg.Done()
                }
            }()
        }
        for i:=0; i<1040; i++ {
            wg.Add(1)
            urls <- fmt.Sprintf("http://www.httpbin.org/get?a=%d", i)
        }
        wg.Wait()
        fmt.Println("Finished")
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have hierarchy like this (This is just a test program. Please
I have this test slider http://jsfiddle.net/dUyLY/2/ In Chrome it works nice, but in firefox
I have this table Test as Id, SomeValue, SomeText contains about a mill records,
I have this problem : Create a program which constructs a lattice of one
I want to unit test my code which will have to create a .java
I'm writing a program which will need to do a very large number of
I have written a Perl program which will match certain words in a log
I have a .NET program which Get Query And Check Spll it. this Query
I have this test [Test] public void SaveInventoryItemLoad_Will_Call_WCF_Service_SaveInventoryItemLoad() { adapter.SaveInventoryItemLoad(new List<InventoryItemLoadProxy>()); itemMasterBusinessClientMock.Verify(x => x.SaveInventoryItemLoad(It.IsAny<List<InventoryItemLoadProxy>>()),
I have this test case def setUp(self): self.user = User.objects.create(username=tauri, password='gaul') def test_loginin_student_control_panel(self): c

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.