-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Milestone
Description
by vladimir.webdev:
Complete code to reproduce:
package main
import (
"fmt"
"websocket"
)
func openConn(ch chan<- int) {
ws, err := websocket.Dial("ws://localhost:9999/", "", "http://
localhost/")
if err != nil {
fmt.Sprintf("Dial: " + err.String())
}
defer ws.Close()
ch <- 1
}
func main() {
ch := make(chan int)
for i := 0; i < 1000; i++ {
go openConn(ch)
}
ch <- 1
}
It fails with:
runtime/cgo: pthread_create failed: Resource temporarily unavailable
SIGABRT: abort
PC=0xf97422
Discussion:
http://groups.google.com/group/golang-nuts/browse_thread/thread/520bdb93d99ee536/a1fdd8c8640cce46#a1fdd8c8640cce46
Quote from 0xe2.0x9a.0...@gmail.com:
The websocket.Dial function is (indirectly) using cgo. Each cgo call
behaves like a syscall. The websocket.Dial() function will try to
allocate C memory when performing address lookup - the memory
allocation (a cgo call) causes the Go runtime to create another OS
thread to handle goroutines. An OS thread (presumably, the newly
created one) calls websocket.Dial() from another goroutine created by
your program, and tries to allocate another piece of C memory, which
in turn creates another OS thread.
This ends up creating too many OS threads.