zanjie1999 / tcp-over-websocket

将TCP/UDP放到WebSocket中传输(就能走CDN)基于ws的内网穿透 隧道代理 tcp2ws 全平台0依赖
291 stars 52 forks source link

WINDOWS连接成功后关闭连接服务出错 #4

Closed Kwan9 closed 2 years ago

Kwan9 commented 2 years ago

2021/12/12 20:31:57 new tcp conn: 2021/12/12 20:31:57 dial ws 9e90 2021/12/12 20:32:21 9e90 tcp read err: read tcp 127.0.0.1:14406->127.0.0.1:4489: wsarecv: An existing connection was forcibly closed by the remote host. 2021/12/12 20:32:21 say bye to 9e90 fatal error: concurrent map read and map write

goroutine 9 [running]: runtime.throw({0xe853f0, 0xc0000563c0}) /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1198 +0x76 fp=0xc00004fe40 sp=0xc00004fe10 pc=0xc26416 runtime.mapaccess1_faststr(0xc000096000, 0xc000164000, {0xc0000b82c0, 0x4}) /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/map_faststr.go:21 +0x3a5 fp=0xc00004fea8 sp=0xc00004fe40 pc=0xc024e5 main.ReadWs2Tcp({0xc0000b82c0, 0x4}) /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:117 +0x43a fp=0xc00004ff90 sp=0xc00004fea8 pc=0xe12aba main.ReadWs2TcpClient({0xc0000b82c0, 0x4}) /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:153 +0x25 fp=0xc00004ffc0 sp=0xc00004ff90 pc=0xe12c25 main.RunClient·dwrap·3() /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:260 +0x2a fp=0xc00004ffe0 sp=0xc00004ffc0 pc=0xe1388a runtime.goexit() /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0xc53481 created by main.RunClient /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:260 +0x3d8

goroutine 1 [chan receive]: main.main() /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:362 +0x6f1

goroutine 6 [IO wait]: internal/poll.runtime_pollWait(0x244e4966708, 0x72) /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/netpoll.go:229 +0x89 internal/poll.(pollDesc).wait(0xc000090160, 0xbfced4, 0x0) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc00007f418, 0xc000063c98) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).acceptOne(0xc00007f400, 0x1a8, {0xc0000860f0, 0xc000148000, 0xc000063d20}, 0xc4fd5b) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_windows.go:810 +0x6d internal/poll.(FD).Accept(0xc00007f400, 0xc000063e70) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_windows.go:844 +0x1d6 net.(netFD).accept(0xc00007f400) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/fd_windows.go:139 +0x65 net.(TCPListener).accept(0xc000004120) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/tcpsock_posix.go:140 +0x28 net.(TCPListener).Accept(0xc000004120) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/tcpsock.go:262 +0x3d main.tcpHandler({0xedbf10, 0xc000004120}) /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:295 +0x5e created by main.main /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:344 +0x2c5

goroutine 7 [syscall]: os/signal.signal_recv() /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/sigqueue.go:169 +0x98 os/signal.loop() /opt/homebrew/Cellar/go/1.17.2/libexec/src/os/signal/signal_unix.go:24 +0x19 created by os/signal.Notify.func1.1 /opt/homebrew/Cellar/go/1.17.2/libexec/src/os/signal/signal.go:151 +0x2c

zanjie1999 commented 2 years ago

更新到最新版,服务和客户端都要更

Kwan9 commented 2 years ago

我昨天下載的就是最新版本耶

zanjie1999 commented 2 years ago

我昨天下載的就是最新版本耶

你都知道是昨天了,那怎么可能是最新版本呢?
用现在的最新版本去试试吧

Kwan9 commented 2 years ago

可以用了 但是另一個業務 又出現錯誤 Server Started ws://0.0.0.0:14605 -> 127.0.0.1:14602 2021/12/13 13:26:54 new ws conn: 127.0.0.1:4876 2021/12/13 13:26:55 new tcp for 96a7 2021/12/13 13:26:55 ws say bye 96a7 fatal error: concurrent map read and map write

goroutine 8 [running]: runtime.throw({0x4b5401, 0xa}) /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1198 +0x76 fp=0xc000205e88 sp=0xc000205e58 pc=0x256416 runtime.mapaccess1_faststr(0x46cac0, 0xc000280000, {0xc00000a630, 0x4}) /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/map_faststr.go:21 +0x3a5 fp=0xc000205ef0 sp=0xc000205e88 pc=0x2324e5 main.ReadTcp2Ws({0xc00000a630, 0x4}) /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:75 +0x567 fp=0xc000205fc0 sp=0xc000205ef0 pc=0x442607 main.RunServer·dwrap·1() /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:213 +0x2a fp=0xc000205fe0 sp=0xc000205fc0 pc=0x44344a runtime.goexit() /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000205fe8 sp=0xc000205fe0 pc=0x283481 created by main.RunServer /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:213 +0x45c

goroutine 1 [chan receive]: main.main() /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:373 +0x6f1

goroutine 19 [IO wait]: internal/poll.runtime_pollWait(0x108ed540e88, 0x72) /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/netpoll.go:229 +0x89 internal/poll.(pollDesc).wait(0xc000046ae0, 0x22ced4, 0x0) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc00005a018, 0xc00004dbb0) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).acceptOne(0xc00005a000, 0x154, {0xc0000600f0, 0x8, 0x108e6c03200}, 0x0) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_windows.go:810 +0x6d internal/poll.(FD).Accept(0xc00005a000, 0xc00004dd88) /opt/homebrew/Cellar/go/1.17.2/libexec/src/internal/poll/fd_windows.go:844 +0x1d6 net.(netFD).accept(0xc00005a000) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/fd_windows.go:139 +0x65 net.(TCPListener).accept(0xc000004060) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/tcpsock_posix.go:140 +0x28 net.(TCPListener).Accept(0xc000004060) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/tcpsock.go:262 +0x3d net/http.(Server).Serve(0xc000058000, {0x50bf70, 0xc000004060}) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/http/server.go:3001 +0x394 net/http.(Server).ListenAndServe(0xc000058000) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/http/server.go:2930 +0x7d net/http.ListenAndServe({0xc0000aa9e0, 0xd}, {0x0, 0x0}) /opt/homebrew/Cellar/go/1.17.2/libexec/src/net/http/server.go:3184 +0x96 created by main.main /Volumes/Files/Go/tcp-over-websocket/tcp2ws.go:340 +0x4f4

goroutine 20 [syscall]: os/signal.signal_recv() /opt/homebrew/Cellar/go/1.17.2/libexec/src/runtime/sigqueue.go:169 +0x98 os/signal.loop() /opt/homebrew/Cellar/go/1.17.2/libexec/src/os/signal/signal_unix.go:24 +0x19 created by os/signal.Notify.func1.1 /opt/homebrew/Cellar/go/1.17.2/libexec/src/os/signal/signal.go:151 +0x2c

zanjie1999 commented 2 years ago

go的map是非线程安全的,而且他没有catch,所以本问题无解
另外我复现不出来,你用来干什么了

Kwan9 commented 2 years ago

用來轉發游戲端口,通過cloudflare

zanjie1999 commented 2 years ago

做了一些修改,在崩掉的时候会自动重连,不会整个端崩掉,可以再试试(

Kwan9 commented 2 years ago

好的,感謝~ 我稍後測試

zanjie1999 commented 2 years ago

写了个锁,问题已修复

Kwan9 commented 2 years ago

感謝修復,經過一天的測試,沒有出現問題。另外我想請問下可以加入心跳包機制嗎? 好像cloudflare的websocket會固定時間斷開

zanjie1999 commented 2 years ago

感謝修復,經過一天的測試,沒有出現問題。另外我想請問下可以加入心跳包機制嗎? 好像cloudflare的websocket會固定時間斷開

早就有心跳包了,ws被掐是会自动重连并且把被掐的这段时间内的包发回去的
如你所见,这些都是心跳 image

Kwan9 commented 2 years ago

明白,平均一小時會斷開一次,這個是cloudflare的原因嗎? image

zanjie1999 commented 2 years ago

如果经过了Nginx,那proxy_read_timeout 3600;这里的3600秒就是1小时断开,就算有收发内容也是1小时断开(相当于一个连接最长可以持续那么久)
如果什么都没有套直接走cf的话,那就是cf掐的,反正断了会重连的,不必担心

Kwan9 commented 2 years ago

好的十分感謝!nginx的timeout設定遠遠超過了3600,那麽應該是cf的原因了。。。另外我想請問下這個重連機制在失敗情況下會嘗試幾次重連呢?因爲我剛剛測試的時候,發現ws斷開後好像沒有重連上。。。於是游戲畫面就卡在那裏了,它也沒有顯示網路中斷,可能是因爲跟ws客戶端還是連接狀態,但是ws并沒有重連到服務端?

zanjie1999 commented 2 years ago

客户端收到tcp内容会用ws发给服务端,这时候如果发现ws断了会重连,没发给服务端的内容会存起来,在下一次连接成功后发过去
服务端收到tcp返回的内容,会找客户端连过来的ws发回去,如果此时断了就会把内容存起来,在下一次客户端重连过来时发过去
服务端会每2分钟发心跳给所有客户端,关闭无法联通ws的客户端的tcp连接(比如在win下直接点叉关掉的客户端)
这个过程中,被转发的tcp连接不会中断

Kwan9 commented 2 years ago

好的,感謝回答!直連nginx測試了5小時都不會斷開,確實是cloudflare每小時都會斷開一次(有時候整點也會斷開,比如15:00)。

Kwan9 commented 2 years ago

又出錯了。。。

xc0001ade48 sp=0xc0001addf0 pc=0x6220fd main.deleteConn({0xc000012638, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:60 +0x3e fp=0 xc0001adec8 sp=0xc0001ade48 pc=0x62239e main.ReadTcp2Ws({0xc000012638, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:101 +0x530 fp =0xc0001adfc0 sp=0xc0001adec8 pc=0x622b10 main.RunServer·dwrap·4() C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:252 +0x2a fp= 0xc0001adfe0 sp=0xc0001adfc0 pc=0x623aaa runtime.goexit() D:/Program Files/Go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc0001adfe8 sp =0xc0001adfe0 pc=0x463481 created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:252 +0x450

goroutine 1 [sleep]: time.Sleep(0x1bf08eb000) D:/Program Files/Go/src/runtime/time.go:193 +0x133 main.main() C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:405 +0x5dd

goroutine 19 [IO wait]: internal/poll.runtime_pollWait(0x28340e88, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0xc0000352e0, 0x40ced4, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc000048018, 0xc000039bb0) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).acceptOne(0xc000048000, 0x2dc, {0xc000058780, 0x47d93f, 0x0} , 0x0) D:/Program Files/Go/src/internal/poll/fd_windows.go:810 +0x6d internal/poll.(FD).Accept(0xc000048000, 0xc000039d88) D:/Program Files/Go/src/internal/poll/fd_windows.go:844 +0x1d6 net.(netFD).accept(0xc000048000) D:/Program Files/Go/src/net/fd_windows.go:139 +0x65 net.(TCPListener).accept(0xc000004060) D:/Program Files/Go/src/net/tcpsock_posix.go:140 +0x28 net.(TCPListener).Accept(0xc000004060) D:/Program Files/Go/src/net/tcpsock.go:262 +0x3d net/http.(Server).Serve(0xc000044000, {0x6ed0d0, 0xc000004060}) D:/Program Files/Go/src/net/http/server.go:3002 +0x394 net/http.(Server).ListenAndServe(0xc000044000) D:/Program Files/Go/src/net/http/server.go:2931 +0x7d net/http.ListenAndServe({0xc0000a89e0, 0xd}, {0x0, 0x0}) D:/Program Files/Go/src/net/http/server.go:3185 +0x96 created by main.main C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:385 +0x4ab

goroutine 3556 [IO wait]: internal/poll.runtime_pollWait(0x2875b2a8, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0x28856000, 0x532d68, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc000061918, 0x6a56c8) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).Read(0xc000061900, {0xc0012c0000, 0x7a120, 0x7a120}) D:/Program Files/Go/src/internal/poll/fd_windows.go:441 +0x25f net.(netFD).Read(0xc000061900, {0xc0012c0000, 0xc00040feb8, 0xa}) D:/Program Files/Go/src/net/fd_posix.go:56 +0x29 net.(conn).Read(0xc0000cc1d8, {0xc0012c0000, 0x6e7f20, 0xc000084be0}) D:/Program Files/Go/src/net/net.go:183 +0x45 main.ReadTcp2Ws({0xc000012680, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:96 +0x143 created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:252 +0x450

goroutine 3574 [IO wait]: internal/poll.runtime_pollWait(0x287800b0, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0x0, 0x2030000, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc0000cf198, 0x6a56c8) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).Read(0xc0000cf180, {0xc000069c00, 0x400, 0x400}) D:/Program Files/Go/src/internal/poll/fd_windows.go:441 +0x25f net.(netFD).Read(0xc0000cf180, {0xc000069c00, 0x0, 0x0}) D:/Program Files/Go/src/net/fd_posix.go:56 +0x29 net.(conn).Read(0xc000006110, {0xc000069c00, 0xc00002bba0, 0x200000003}) D:/Program Files/Go/src/net/net.go:183 +0x45 bufio.(Reader).fill(0xc0000ff7a0) D:/Program Files/Go/src/bufio/bufio.go:101 +0x103 bufio.(Reader).Peek(0xc0000ff7a0, 0x2) D:/Program Files/Go/src/bufio/bufio.go:139 +0x5d github.com/gorilla/websocket.(Conn).read(0xc00006f600, 0xc000046820) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :370 +0x2c github.com/gorilla/websocket.(Conn).advanceFrame(0xc00006f600) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :798 +0x7b github.com/gorilla/websocket.(Conn).NextReader(0xc00006f600) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :980 +0xc5 github.com/gorilla/websocket.(Conn).ReadMessage(0xc0000a8640) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :1064 +0x19 main.ReadWs2Tcp({0xc0000a8640, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:154 +0x13a created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:257 +0x49b

goroutine 3577 [IO wait]: internal/poll.runtime_pollWait(0x28781100, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0x28871a00, 0x2030000, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc00017a298, 0x6a56c8) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).Read(0xc00017a280, {0xc001434000, 0x7a120, 0x7a120}) D:/Program Files/Go/src/internal/poll/fd_windows.go:441 +0x25f net.(netFD).Read(0xc00017a280, {0xc001434000, 0xc0003b3eb8, 0xa}) D:/Program Files/Go/src/net/fd_posix.go:56 +0x29 net.(conn).Read(0xc000006138, {0xc001434000, 0x6e7f20, 0xc000084be0}) D:/Program Files/Go/src/net/net.go:183 +0x45 main.ReadTcp2Ws({0xc0000a8688, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:96 +0x143 created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:252 +0x450

goroutine 3587 [IO wait]: internal/poll.runtime_pollWait(0x2875e268, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0x28879600, 0x532d68, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc00017aa18, 0x6a56c8) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).Read(0xc00017aa00, {0xc00152c000, 0x7a120, 0x7a120}) D:/Program Files/Go/src/internal/poll/fd_windows.go:441 +0x25f net.(netFD).Read(0xc00017aa00, {0xc00152c000, 0xc0001bbeb8, 0xa}) D:/Program Files/Go/src/net/fd_posix.go:56 +0x29 net.(conn).Read(0xc000006168, {0xc00152c000, 0x6e7f20, 0xc000084be0}) D:/Program Files/Go/src/net/net.go:183 +0x45 main.ReadTcp2Ws({0xc0000a87c8, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:96 +0x143 created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:252 +0x450

goroutine 3570 [IO wait]: internal/poll.runtime_pollWait(0x2875b648, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0x0, 0x2030000, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc000061b98, 0x6a56c8) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).Read(0xc000061b80, {0xc000170400, 0x400, 0x400}) D:/Program Files/Go/src/internal/poll/fd_windows.go:441 +0x25f net.(netFD).Read(0xc000061b80, {0xc000170400, 0xc000125cb0, 0x416f86}) D:/Program Files/Go/src/net/fd_posix.go:56 +0x29 net.(conn).Read(0xc0000cc1e0, {0xc000170400, 0xc000048b18, 0xc000048b28}) D:/Program Files/Go/src/net/net.go:183 +0x45 bufio.(Reader).fill(0xc0000430e0) D:/Program Files/Go/src/bufio/bufio.go:101 +0x103 bufio.(Reader).Peek(0xc0000430e0, 0x2) D:/Program Files/Go/src/bufio/bufio.go:139 +0x5d github.com/gorilla/websocket.(Conn).read(0xc000174000, 0xc0000468c0) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :370 +0x2c github.com/gorilla/websocket.(Conn).advanceFrame(0xc000174000) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :798 +0x7b github.com/gorilla/websocket.(Conn).NextReader(0xc000174000) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :980 +0xc5 github.com/gorilla/websocket.(Conn).ReadMessage(0xc0000a85f8) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :1064 +0x19 main.ReadWs2Tcp({0xc0000a85f8, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:154 +0x13a created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:257 +0x49b

goroutine 3557 [runnable, locked to thread]: syscall.Syscall6(0x76ff31e0, 0x5, 0xb, 0xc000016a00, 0x24, 0xc0002a3808, 0x0, 0x 0) D:/Program Files/Go/src/runtime/syscall_windows.go:497 +0xfa syscall.WriteConsole(0xc0002a3860, 0xc000016a00, 0x24, 0xc0002a3808, 0x0) D:/Program Files/Go/src/syscall/zsyscall_windows.go:1154 +0xb3 internal/poll.(FD).writeConsole(0xc0000ce500, {0xc000074000, 0x24, 0xc067c4d3cf fce1bc}) D:/Program Files/Go/src/internal/poll/fd_windows.go:683 +0x4f5 internal/poll.(FD).Write(0xc0000ce500, {0xc000074000, 0x24, 0xa0}) D:/Program Files/Go/src/internal/poll/fd_windows.go:618 +0x23d os.(File).write(...) D:/Program Files/Go/src/os/file_posix.go:49 os.(File).Write(0xc0000cc010, {0xc000074000, 0xf, 0xf30108}) D:/Program Files/Go/src/os/file.go:176 +0x65 log.(*Logger).Output(0xc0000800a0, 0x2, {0xc000012900, 0xf}) D:/Program Files/Go/src/log/log.go:184 +0x368 log.Print({0xc0002a3f58, 0x4, 0xf39218}) D:/Program Files/Go/src/log/log.go:317 +0x38 main.ReadWs2Tcp({0xc000012680, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:171 +0x327 created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:257 +0x49b

goroutine 3537 [IO wait]: internal/poll.runtime_pollWait(0x2877f7a0, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0x28859e00, 0x461155, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc0000cef18, 0x6a56c8) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).Read(0xc0000cef00, {0xc00133c000, 0x7a120, 0x7a120}) D:/Program Files/Go/src/internal/poll/fd_windows.go:441 +0x25f net.(netFD).Read(0xc0000cef00, {0xc00133c000, 0xc0002c7eb8, 0xa}) D:/Program Files/Go/src/net/fd_posix.go:56 +0x29 net.(conn).Read(0xc000006108, {0xc00133c000, 0x6e7f20, 0xc000084be0}) D:/Program Files/Go/src/net/net.go:183 +0x45 main.ReadTcp2Ws({0xc0000a85f8, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:96 +0x143 created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:252 +0x450

goroutine 3578 [IO wait]: internal/poll.runtime_pollWait(0x2877f970, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0x0, 0x0, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc00017a018, 0x6a56c8) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).Read(0xc00017a000, {0xc0001ce000, 0x400, 0x400}) D:/Program Files/Go/src/internal/poll/fd_windows.go:441 +0x25f net.(netFD).Read(0xc00017a000, {0xc0001ce000, 0x0, 0x0}) D:/Program Files/Go/src/net/fd_posix.go:56 +0x29 net.(conn).Read(0xc000006128, {0xc0001ce000, 0xc000060618, 0xc000060628}) D:/Program Files/Go/src/net/net.go:183 +0x45 bufio.(Reader).fill(0xc0000ffa40) D:/Program Files/Go/src/bufio/bufio.go:101 +0x103 bufio.(Reader).Peek(0xc0000ffa40, 0x2) D:/Program Files/Go/src/bufio/bufio.go:139 +0x5d github.com/gorilla/websocket.(Conn).read(0xc00006fb80, 0xc0000808c0) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :370 +0x2c github.com/gorilla/websocket.(Conn).advanceFrame(0xc00006fb80) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :798 +0x7b github.com/gorilla/websocket.(Conn).NextReader(0xc00006fb80) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :980 +0xc5 github.com/gorilla/websocket.(Conn).ReadMessage(0xc0000a8688) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :1064 +0x19 main.ReadWs2Tcp({0xc0000a8688, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:154 +0x13a created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:257 +0x49b

goroutine 3573 [IO wait]: internal/poll.runtime_pollWait(0x28780198, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0x28870000, 0x461155, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc0000cf418, 0x6a56c8) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).Read(0xc0000cf400, {0xc0013b8000, 0x7a120, 0x7a120}) D:/Program Files/Go/src/internal/poll/fd_windows.go:441 +0x25f net.(netFD).Read(0xc0000cf400, {0xc0013b8000, 0xc0003fdeb8, 0xa}) D:/Program Files/Go/src/net/fd_posix.go:56 +0x29 net.(conn).Read(0xc000006120, {0xc0013b8000, 0x6e7f20, 0xc000084be0}) D:/Program Files/Go/src/net/net.go:183 +0x45 main.ReadTcp2Ws({0xc0000a8640, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:96 +0x143 created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:252 +0x450

goroutine 3588 [IO wait]: internal/poll.runtime_pollWait(0x28780e48, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0x0, 0x2030000, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc00017a798, 0x6a56c8) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).Read(0xc00017a780, {0xc000170c00, 0x400, 0x400}) D:/Program Files/Go/src/internal/poll/fd_windows.go:441 +0x25f net.(netFD).Read(0xc00017a780, {0xc000170c00, 0xc0003c5cb0, 0x416f86}) D:/Program Files/Go/src/net/fd_posix.go:56 +0x29 net.(conn).Read(0xc000006158, {0xc000170c00, 0xc0000cfc98, 0xc0000cfca8}) D:/Program Files/Go/src/net/net.go:183 +0x45 bufio.(Reader).fill(0xc000043260) D:/Program Files/Go/src/bufio/bufio.go:101 +0x103 bufio.(Reader).Peek(0xc000043260, 0x2) D:/Program Files/Go/src/bufio/bufio.go:139 +0x5d github.com/gorilla/websocket.(Conn).read(0xc000174420, 0xc000046550) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :370 +0x2c github.com/gorilla/websocket.(Conn).advanceFrame(0xc000174420) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :798 +0x7b github.com/gorilla/websocket.(Conn).NextReader(0xc000174420) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :980 +0xc5 github.com/gorilla/websocket.(Conn).ReadMessage(0xc0000a87c8) C:/Users/Kwanwing/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go :1064 +0x19 main.ReadWs2Tcp({0xc0000a87c8, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:154 +0x13a created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:257 +0x49b

C:\Users\Administrator\Desktop>

Kwan9 commented 2 years ago

fatal error: concurrent map read and map write

goroutine 883 [running]: runtime.throw({0x696467, 0x8935c0}) D:/Program Files/Go/src/runtime/panic.go:1198 +0x76 fp=0xc0000bbd88 sp= xc0000bbd58 pc=0x436416 runtime.mapaccess2_faststr(0x0, 0x0, {0xc0000120a8, 0x4}) D:/Program Files/Go/src/runtime/map_faststr.go:116 +0x3d4 fp=0xc0000bbd 0 sp=0xc0000bbd88 pc=0x4128f4 main.getConn({0xc0000120a8, 0xc0000440d0}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:49 +0xbd fp= xc0000bbe48 sp=0xc0000bbdf0 pc=0x6220fd main.deleteConn({0xc0000120a8, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:60 +0x3e fp= xc0000bbec8 sp=0xc0000bbe48 pc=0x62239e main.ReadTcp2Ws({0xc0000120a8, 0x4}) C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:101 +0x530 f =0xc0000bbfc0 sp=0xc0000bbec8 pc=0x622b10 main.RunServer·dwrap·4() C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:252 +0x2a fp 0xc0000bbfe0 sp=0xc0000bbfc0 pc=0x623aaa runtime.goexit() D:/Program Files/Go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc0000bbfe8 s =0xc0000bbfe0 pc=0x463481 created by main.RunServer C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:252 +0x450

goroutine 1 [sleep, 4 minutes]: time.Sleep(0x1bf08eb000) D:/Program Files/Go/src/runtime/time.go:193 +0x133 main.main() C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:405 +0x5dd

goroutine 6 [IO wait]: internal/poll.runtime_pollWait(0x23d4e88, 0x72) D:/Program Files/Go/src/runtime/netpoll.go:234 +0x89 internal/poll.(pollDesc).wait(0xc00003fba8, 0x40ced4, 0x0) D:/Program Files/Go/src/internal/poll/fd_poll_runtime.go:84 +0x32 internal/poll.execIO(0xc000098018, 0xc00003fbb0) D:/Program Files/Go/src/internal/poll/fd_windows.go:175 +0xe5 internal/poll.(FD).acceptOne(0xc000098000, 0x12c, {0xc00005e0f0, 0x47d93f, 0x0 , 0x0) D:/Program Files/Go/src/internal/poll/fd_windows.go:810 +0x6d internal/poll.(FD).Accept(0xc000098000, 0xc00003fd88) D:/Program Files/Go/src/internal/poll/fd_windows.go:844 +0x1d6 net.(netFD).accept(0xc000098000) D:/Program Files/Go/src/net/fd_windows.go:139 +0x65 net.(TCPListener).accept(0xc000092048) D:/Program Files/Go/src/net/tcpsock_posix.go:140 +0x28 net.(TCPListener).Accept(0xc000092048) D:/Program Files/Go/src/net/tcpsock.go:262 +0x3d net/http.(Server).Serve(0xc000086000, {0x6ed0d0, 0xc000092048}) D:/Program Files/Go/src/net/http/server.go:3002 +0x394 net/http.(Server).ListenAndServe(0xc000086000) D:/Program Files/Go/src/net/http/server.go:2931 +0x7d net/http.ListenAndServe({0xc000012a10, 0xd}, {0x0, 0x0}) D:/Program Files/Go/src/net/http/server.go:3185 +0x96 created by main.main C:/Users/Kwanwing/Desktop/tcp-over-websocket-5.0/tcp2ws.go:385 +0x4ab

zanjie1999 commented 2 years ago

上面这个49行报错的是哪个版本?行号对不上了😂,另外有读写互斥锁,不应该出现这个读写冲突的错误
之前服务端客户端都有更新到最新的版本吗?

Kwan9 commented 2 years ago

兩次抱錯都是沒支持ssl前的那個版本喔

zanjie1999 commented 2 years ago

我找到了,那版二进制文件在174行有个delete没有上锁,在6.0开始的二进制文件已经是改掉这个问题的了

Kwan9 commented 2 years ago

好的我今天換版本測試