title: Golang how can I stop an Http request from continuing to fire
body: <p>I was doing some load testing earlier today and found something peculiar, sometimes an Http request doesn't not die and keeps on firing . How can I correct that in my Golang code for instance see the image below . I am load testing loading 1,000 HTTP request but if you notice on the 1,000th request below it takes 392,999 milliseconds or <strong>392 seconds</strong> while the rest of the request takes <strong>2.2 seconds</strong> on average . I have done the test multiple times and sometimes it hangs . This is my code</p>
  
  <pre><code>func Home_streams(w http.ResponseWriter, r *http.Request) {
      var result string
  
      r.ParseForm()
  
      wg := sync.WaitGroup{}
  
      wg.Add(1)
      go func() {
  
  
      defer wg.Done()
  
      db.QueryRow("select json_build_object('Locations', array_to_json(array_agg(t))) from (SELECT latitudes,county,longitudes,"+
          "statelong,thirtylatmin,thirtylatmax,thirtylonmin,thirtylonmax,city"+
          " FROM zips where city='Orlando' ORDER BY city limit 5) t").Scan(&amp;result)
  
      }()
      wg.Wait()
  
      fmt.Fprintf(w,result)
  }
  </code></pre>
  
  <p>and I connect to the database with this code</p>
  
  <pre><code>func init() {
      var err error
      db, err = sql.Open("postgres","Postgres Connection String")
  
      if err != nil {
          log.Fatal("Invalid DB config:", err)
      }
      if err = db.Ping(); err != nil {
          log.Fatal("DB unreachable:", err)
      }
  }
  </code></pre>
  
  <p>I would say that about 10 % of the time I load test this issue happens and the only way it stops is if I stop the requests manually otherwise it keeps on going indefinitely . I wonder if maybe this issue is addressed here <a href="https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779#.83uzpsp24" rel="nofollow noreferrer">https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779#.83uzpsp24</a>  I am still learning my way around Golang .
  <a href="https://i.stack.imgur.com/DiJND.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DiJND.png" alt="enter image description here"></a></p>