Go, tcp too many open files debug

前端 未结 6 864
有刺的猬
有刺的猬 2020-12-08 20:32

Here\'s a straightforward Go http (tcp) connection test script

func main() {
    ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *htt         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 20:40

    I think you need to change your max file descriptors. I have run into the same problem on one of my development VMs before and needed to change the file descriptors max, not anything with inotify settings.

    FWIW, your program runs fine on my VM.

    ·> ulimit -n
    120000
    

    But after I run

    ·> ulimit -n 500
    ·> ulimit -n
    500
    

    I get:

    panic: Get http://127.0.0.1:51227: dial tcp 127.0.0.1:51227: socket: too many open files
    

    ** Don't fall into the trap that Praveen did **

    Note ulimit != ulimit -n.

    ➜  cmd git:(wip-poop) ✗ ulimit -a
    -t: cpu time (seconds)              unlimited
    -f: file size (blocks)              unlimited
    -d: data seg size (kbytes)          unlimited
    -s: stack size (kbytes)             8192
    -c: core file size (blocks)         0
    -v: address space (kbytes)          unlimited
    -l: locked-in-memory size (kbytes)  unlimited
    -u: processes                       1418
    -n: file descriptors                4864
    

提交回复
热议问题