gopherjs / websocket

websocket provides high- and low-level bindings for the browser's WebSocket API.
BSD 3-Clause "New" or "Revised" License
111 stars 25 forks source link

Import of net package causes os.Open syscall in net.maxListenerBacklog #8

Closed nwidger closed 9 years ago

nwidger commented 9 years ago

I just ran into an issue using the latest versions of github.com/gopherjs/gopherjs and github.com/gopherjs/websocket wihch seems to be caused by websocket pulling in the stdlib net package. net has a global variable var listenerBacklog = maxListenerBacklog() in net/net.go which gets initialized during package initialization. In the browser at runtime this initialization causes a call to os.Open("/proc/sys/net/core/somaxconn") which triggers the following error on the JS console:

warning: system calls not available, see https://github.com/gopherjs/gopherjs/blob/master/doc/syscalls.md

The solution that worked for me was to add the following stub to github.com/gopherjs/gopherjs/compiler/natives/net/net.go:

func maxListenerBacklog() int {
    return 0x80
}

where 0x80 is the value of syscall.SOMAXCONN for Linux. I'm using Go 1.4.1 on linux_amd64.

mjohnson9 commented 9 years ago

I believe you should create an issue in the gopherjs project. Previously, the same issue existed when built with Windows and was filed under gopherjs/gopherjs#123.

Alternatively, we can stop importing the net package, though we would no longer implement the net.Conn interface. (basically, we'd need to revert #6.)

nwidger commented 9 years ago

Oops, you're absolutely right. I'll open a ticket with gopherjs, sorry!

mjohnson9 commented 9 years ago

No worries! Thanks for reporting the bug. :+1: