Too Many Open File Error in Golang
<p>I am simply reading the <code>/proc/diskstats</code> file.  My code is:</p>

<pre><code>func ReadFromFile(filepath string)(string){
    defer func() {
        if err1 := recover(); err1 != nil {
            fmt.Println("!!!!!!!!!!!!!!!!Panic Occured and Recovered in readFromFile(), Error Info: ", err1)
        }
     }()

    strData := ""

    data, err := ioutil.ReadFile(filepath)
    if err != nil{
        fmt.Println("File read error: ", err)
        return ""
    }

    strData = string(data)
    return strData
}
</code></pre>

<p>The error I am getting is:</p>

<pre><code>File read error: open /proc/diskstats: too many open files
</code></pre>

<p>Not only for this file, I am also getting the same error for some other files.</p>

<p>I have also run this command:</p>

<pre><code>root@golang:~# lsof|wc -l

785
</code></pre>

<p>Please guide me.</p>