We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows下使用gnet2.3.0时似乎有bug,使用gnet.Client.Dial返回一个conn时,直接调用conn.Wake, 会唤起OnTraffic,如果此时在OnTraffic方法中从conn中读取数据,立马就空指针崩溃了,因为此时windows下的实现的conn的buffer为nil,简单的复现代码如下。在linux环境下表现正常。至于为什么要立马调用Wake方法,是因为我在项目中想通过Wake的回调来设置Context,因为conn.Context和GetContext都不是并发安全的
v2
v2.3.0
Windows
10 22H2
go 1.17
panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x8 pc=0x584942] goroutine 6 [running]: github.com/valyala/bytebufferpool.(*ByteBuffer).Len(...) C:/Users/*****/go/pkg/mod/github.com/valyala/bytebufferpool@v1.0.0/byte buffer.go:21 github.com/panjf2000/gnet/v2.(*conn).Peek(0xc00005be50, 0x425fc5) C:/Users/*****/go/pkg/mod/github.com/panjf2000/gnet/v2@v2.3.0/connectio n_windows.go:164 +0x62 main.(*clientEvents).OnTraffic(0x0, {0x61efc0, 0xc0000244e0}) C:/Workspace/Code/Go/go-sample/gnet_test/examples/client/main.go:19 +0x2 f github.com/panjf2000/gnet/v2.(*eventloop).wake(0xc000024480, 0xc0000244e0) C:/Users/*****/go/pkg/mod/github.com/panjf2000/gnet/v2@v2.3.0/eventloop _windows.go:178 +0x5b github.com/panjf2000/gnet/v2.(*conn).Wake.func2() C:/Users/*****/go/pkg/mod/github.com/panjf2000/gnet/v2@v2.3.0/connectio n_windows.go:437 +0x7b github.com/panjf2000/gnet/v2.(*eventloop).run(0xc000024480) C:/Users/*****/go/pkg/mod/github.com/panjf2000/gnet/v2@v2.3.0/eventloop _windows.go:79 +0x1f3 golang.org/x/sync/errgroup.(*Group).Go.func1() C:/Users/*****/go/pkg/mod/golang.org/x/sync@v0.2.0/errgroup/errgroup.go :75 +0x64 created by golang.org/x/sync/errgroup.(*Group).Go C:/Users/*****/go/pkg/mod/golang.org/x/sync@v0.2.0/errgroup/errgroup.go :72 +0xa9
package main import ( "github.com/panjf2000/gnet/v2" "github.com/panjf2000/gnet/v2/pkg/logging" "log" "time" ) type clientEvents struct { *gnet.BuiltinEventEngine } func (ev *clientEvents) OnBoot(e gnet.Engine) gnet.Action { return gnet.None } func (ev *clientEvents) OnTraffic(c gnet.Conn) (action gnet.Action) { _, err := c.Peek(10) if err != nil { log.Println(err) } return gnet.None } func main() { ev := &clientEvents{} client, _ := gnet.NewClient(ev, gnet.WithLogLevel(logging.DebugLevel), gnet.WithLockOSThread(true)) client.Start() conn, _ := client.Dial("tcp", ":7399") conn.Wake(func(c gnet.Conn, err error) error { return nil }) for { time.Sleep(time.Second * 10) } }
Steps to reproduce the behavior:
I haven't verified it with the latest release
The text was updated successfully, but these errors were encountered:
如果只是要设置 context,在 OnOpen 里设置不就行了?
OnOpen
Sorry, something went wrong.
bug: fix the inconsistent behaviors on Windows
a6a1878
Fixes #509
正如我前面说所,你的使用应该是有问题,不过考虑到这里确实存在代码在 Windows 和其他操作系统上行为不一致的问题,所以,还是要修复一下。
5710ad4
panjf2000
No branches or pull requests
Actions I've taken before I'm here
What happened?
windows下使用gnet2.3.0时似乎有bug,使用gnet.Client.Dial返回一个conn时,直接调用conn.Wake, 会唤起OnTraffic,如果此时在OnTraffic方法中从conn中读取数据,立马就空指针崩溃了,因为此时windows下的实现的conn的buffer为nil,简单的复现代码如下。在linux环境下表现正常。至于为什么要立马调用Wake方法,是因为我在项目中想通过Wake的回调来设置Context,因为conn.Context和GetContext都不是并发安全的
Major version of gnet
v2
Specific version of gnet
v2.3.0
Operating system
Windows
OS version
10 22H2
Go version
go 1.17
Relevant log output
Code snippets (optional)
How to Reproduce
Steps to reproduce the behavior:
Does this issue reproduce with the latest release?
I haven't verified it with the latest release
The text was updated successfully, but these errors were encountered: