title: Go runtime error: panic: runtime error: invalid memory address or nil pointer dereference
body: <p>My code run normaly in a few second but after that, it throws an error:</p>
  <blockquote>
  <p>panic: runtime error: invalid memory address or nil pointer
  dereference</p>
  <p>panic: runtime error: invalid memory address or nil pointer
  dereference [signal SIGSEGV: segmentation violation code=0x1
  addr=0x328 pc=0x58d086]</p>
  <p>goroutine 1884 [running]: crypto/tls.(*Conn).Close(0x0, 0x0, 0x0)
  /usr/local/go/src/crypto/tls/conn.go:1310 +0x26 panic(0x5dcc60, 0x73dc30)
  /usr/local/go/src/runtime/panic.go:965 +0x1b9 crypto/tls.(*Conn).Write(0x0, 0xc000701fb0, 0x23, 0x30, 0x0, 0x0, 0x0)
  /usr/local/go/src/crypto/tls/conn.go:1101 +0x66 main.main.func1(0xc0000aa270, 0xd, 0x60d313, 0x9)
  /home/nt-user/workspace/Main.go:28 +0x19b created by main.main
  /home/nt-user/workspace/Main.go:18 +0xbf exit status 2</p>
  </blockquote>
  <pre><code>package main
  
  import (
      //&quot;net&quot;
      &quot;time&quot;
      &quot;fmt&quot;
      &quot;crypto/tls&quot;
  )
  
  func main() {
      var (
          targetHost = &quot;Website URL&quot;
          targetPort = &quot;443&quot;
          targetURL = targetHost + &quot;:&quot; + targetPort
      )
      for true {
          for i := 0; i &lt; 500; i++ {
              go func() {
                 var s, err = tls.Dial(&quot;tcp&quot;, targetURL, &amp;tls.Config {
                     ServerName: targetHost,
                     InsecureSkipVerify: true,
                 })
                 if err != nil {
                     fmt.Println(&quot;Error when connect to &quot; + targetHost)
                 }
                 defer s.Close()
                 for i := 0; i &lt; 100; i++ {
                     s.Write([]byte(&quot;GET / HTTP/1.1\r\nHost: &quot; + targetHost + &quot;\r\n\r\n&quot;))
                 }
              }()
          }
          time.Sleep(1 * time.Second)
      }
  }
  </code></pre>
  <p>How can I fix it?</p>