Gopherjs: Importing "net" causes runtime error?

Created on 17 Mar 2016  路  7Comments  路  Source: gopherjs/gopherjs

I dunno if I've set something up incorrectly but if I build this with the latest gopherjs:

package main

import (
    "fmt"
    "net"
)

func main() {
    var thing net.Conn
    fmt.Printf("Thing: %v", thing)
}

I get "Error: system calls not available, see..." in both Firefox and Chrome. I assume someone else would've made the issue if it was replicable but I'm posting this just in case. It seems like a syscall is being triggered when the "net" package is initialized because this:

package main

import (
    _ "net"
)

func main() {
}

has the same effect.

Most helpful comment

Okay, so this is a Windows specific issue. I think we can simply mock probeWindowsIPStack with an empty function, because there is no support for syscalls on Windows at all.

All 7 comments

Save for the fact that syscalls are unsupported in the browser, yeah :)

Perhaps this should have been posted in the gopherjs/websocket package but it seems any package that includes net now creates a runtime error on initialization of the net package. Prior to Go 1.6 this didn't happen. I'm aware that net is listed as unsupported in gopherjs but it used to be possible to include it for just the interfaces/errors/struct definitions.

I think this is a bug. Importing net should not yet cause an error.

@nytehauq Could you please check what the init function attempts to do?

Yeah, it seems like net.go (line 99) calls probeIPv4Stack() which seems to be translated into a platform specific function like probeWindowsIPStack(), which in turn calls Syscall.GetVersion() and then the trace descends into the weeds:

testing.js:1405 Uncaught Error: system calls not available, see https://github.com/gopherjs/gopherjs/blob/master/doc/syscalls.md

$callDeferred @ testing.js:1405
$panic @ testing.js:1444
$packages.syscall.LazyProc.ptr.mustFind @ dll_windows.go:259
$packages.syscall.LazyProc.ptr.Addr @ dll_windows.go:266
$packages.syscall.GetVersion @ zsyscall_windows.go:231
$packages.net.probeWindowsIPStack @ interface_windows.go:23
$packages.net.init$1 @ interface_windows.go:19
$packages.net.$init @ testing.js:10837
$packages.testing/testing.$init @ testing.js:10853
$goroutine @ testing.js:1464
$schedule @ testing.js:1521
$go @ testing.js:1497
(anonymous function) @ testing.js:10866
(anonymous function) @ testing.js:10869

Okay, so this is a Windows specific issue. I think we can simply mock probeWindowsIPStack with an empty function, because there is no support for syscalls on Windows at all.

Also referenced here, in the gophejs/websocket lib

https://github.com/gopherjs/websocket/issues/17

Unfortunately, the latest commit edfe1438a4184bea0b3f9e35fd77969061676d9c requires that app code must import the "net" package in order to use websockets. This breaks builds on Windows.

Resolved by #438.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hackwaly picture hackwaly  路  4Comments

4ydx picture 4ydx  路  3Comments

hajimehoshi picture hajimehoshi  路  6Comments

marwan-at-work picture marwan-at-work  路  4Comments

hajimehoshi picture hajimehoshi  路  6Comments