panjf2000 / gnet

🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.

Home Page:https://gnet.host

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Calling Dial() in version 2.4 of Windows 10 will block

Fish-watching-the-sea opened this issue · comments

Actions I've taken before I'm here

  • I've thoroughly read the documentations on this issue but still have no clue.
  • I've searched the Github Issues but didn't find any duplicate issues that have been resolved.
  • I've searched the internet for this issue but didn't find anything helpful.

What happened?

哈罗,我正在 Windows 进行调试,但是我发现 2.4 版本在 Windows 下调用 gnet.Client.Dial() 方法时会长时间阻塞,且不会返回超时等异常。
2.3.4 版本正常。
使用 tcp 连接也会长时间阻塞。

Major version of gnet

v2

Specific version of gnet

2.4

Operating system

Windows

OS version

Windows 10 10.0.19044 N/A Build 19044

Go version

go version go1.21.3 windows/amd64

Relevant log output

PS E:\Project\Go\test_gnet_2.4> go test -v
=== RUN   TestGnet
    gnet_test.go:29: 1

Code snippets (optional)

package testgnet24

import (
	"net"
	"testing"

	"github.com/panjf2000/gnet/v2"
)

type NetManager struct {
	gnet.BuiltinEventEngine
}

func TestGnet(t *testing.T) {
	// 监听一个端口
	conn, err := net.ListenUDP("udp", &net.UDPAddr{
		IP:   net.ParseIP("0.0.0.0"),
		Port: 9871,
	})
	if err != nil {
		t.Fatal(err)
	}

	metManager := &NetManager{}
	cli, err := gnet.NewClient(metManager)
	if err != nil {
		t.Fatal(err)
	}
	t.Log("1")

	c, err := cli.Dial("udp", "127.0.0.1:9871")
	if err != nil {
		t.Fatal(err)
	}
	t.Log("2")

	err = conn.Close()
	if err != nil {
		t.Fatal(err)
	}

	err = c.Close()
	if err != nil {
		t.Fatal(err)
	}
}

How to Reproduce

go test -v

Does this issue reproduce with the latest release?

It can reproduce with the latest release

找到问题了,问题

🤖 Non-English text detected, translating...


Found the problem, problem

需要先调用 gnet.Client.Start() 再调用 gnet.Client.Dial()

🤖 Non-English text detected, translating...


You need to call gnet.Client.Start() first and then gnet.Client.Dial().