<p dir="auto">by <strong>an2048</strong>:</p>
<pre class="notranslate">What steps will reproduce the problem?
Build and run the drawing example (or any other) from the Walk project
(<a href="https://github.com/lxn/walk)">https://github.com/lxn/walk)</a>

What is the expected output?
The program should not panic.

What do you see instead?
throw: too many callback functions

runtime.throw+0x42 /go/src/pkg/runtime/runtime.c:102
    runtime.throw(0x931e5b, 0x5)
runtime.compilecallback+0xe4 /go/src/pkg/runtime/windows/thread.c:377
    runtime.compilecallback(0x6462ec, 0x4ffd87, 0x10f39501, 0x4ffab0)
syscall.NewCallback+0x39 /go/src/pkg/runtime/windows/syscall.c:26
    syscall.NewCallback(0x6462ec, 0x4ffd87, 0x6462ec, 0x4ffd87)
walk.init·2+0xff
C:/devel/projects/eclipse_workspace/walk/src/pkg/walk/webview_ioleinplaceframe.go:37
    walk.init·2()
walk.init+0x597 C:/devel/projects/eclipse_workspace/walk/src/pkg/walk/action.go:233
    walk.init()
main.init+0x78
C:/devel/projects/eclipse_workspace/picos-order/src/cmd/picos-order/orderpoolpage.go:24
    main.init()
runtime.mainstart+0x5 386/asm.s:91
    runtime.mainstart()
runtime.goexit /go/src/pkg/runtime/proc.c:178
    runtime.goexit()
----- goroutine created by -----
_rt0_386+0xbf 386/asm.s:80

Which compiler are you using (5g, 6g, 8g, gccgo)?
8g

Which operating system are you using?
Windows XP SP3

Which revision are you using?  (hg identify)
3418f22c39eb weekly/weekly.2011-06-02

Please provide any additional information below.
The problem was introduced by 95553202a7a8 - runtime: do not garbage collect windows
callbacks</pre>
<pre class="notranslate">-- from code review 5574063: net: disable SO_REUSEADDR and SO_REUSEPORT on openbsd
(<a href="https://golang.org/issue/5574063" rel="nofollow">issue #5574063</a>) on golang-dev

Sorry, I should have been more specific here. The problem is not due
to use of SO_REUSEADDR on the listening socket - the issue is that we
are setting it on all sockets. As a result, the client performs a
connect() which results in the allocation of a randomised port number
- since SO_REUSEADDR/SO_REUSEPORT are enabled the port number is
permitted to already be in use and the normal duplication checks are
not performed. We then attempt to establish a TCP connection using
this already in use port number, which fails:

 19425 test.out CALL  socket(PF_INET,SOCK_STREAM,IPPROTO_IP)
 19425 test.out RET   socket 10/0xa
 19425 test.out CALL  fcntl(0xa,F_SETFD,FD_CLOEXEC)
 19425 test.out RET   fcntl 0
 19425 test.out CALL  setsockopt(0xa,SOL_SOCKET,SO_REUSEADDR,0xf84019ea00,0x4)
 19425 test.out RET   setsockopt 0
 19425 test.out CALL  setsockopt(0xa,SOL_SOCKET,SO_REUSEPORT,0xf84019ea08,0x4)
 19425 test.out RET   setsockopt 0
 19425 test.out CALL  setsockopt(0xa,SOL_SOCKET,SO_BROADCAST,0xf84019ea10,0x4)
 19425 test.out RET   setsockopt 0
 19425 test.out CALL  fcntl(0xa,F_GETFL,0)
 19425 test.out RET   fcntl 2
 19425 test.out CALL  fcntl(0xa,F_SETFL,0x6&lt;O_RDWR|O_NONBLOCK&gt;)
 19425 test.out RET   fcntl 0
 19425 test.out CALL  connect(0xa,0xf840186768,0x10)
 19425 test.out STRU  struct sockaddr { AF_INET, 127.0.0.1:43658 }
 19425 test.out RET   connect -1 errno 48 Address already in use

The other (and probably better) solution is to only set
SO_REUSEADDR/SO_REUSEPORT on sockets that will be listening, probably
via the addition of a func setDefaultListenSockopts(fd *netFD) that
would be called from ListenTCP() et al.</pre>