New issue
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
centos6.5 32位系统下 RussellLuo/timingwheel 运行后 panic #8
Comments
从报错信息来看,是 timingwheel 库的 bug,我会尽快修复。 |
timingwheel 库现在已经支持 定时任务,所以我将自己临时修改的 timingwheel 库替换。 老哥,你再测试看看。 我本地测试是没有问题的,你方便的话,发下你的测试脚本。 |
测试脚本就是这个项目里面的 example/pushmessage/main.go 还是这个报错,是不是不支持centos6.5呢? centos7里面跑就对的 panic: runtime error: invalid memory address or nil pointer dereference goroutine 1 [running]: |
你把你的执行命令 和 回显 信息都贴上来我看看 |
这样? 这个main.go就是复制的 pushmessage/main.go goroutine 1 [running]: |
你把 main.go 也贴出来把 |
package main import ( type Server struct { func New(ip, port string) (*Server, error) {
} func (s *Server) Start() {
} func (s *Server) Stop() { func (s *Server) RunPush() {
} func (s *Server) OnConnect(c *connection.Connection) {
} func (s *Server) OnClose(c *connection.Connection) {
} func main() {
} |
package main
import (
"container/list"
"github.com/Allenxuxu/gev"
"github.com/Allenxuxu/gev/connection"
"github.com/Allenxuxu/ringbuffer"
"log"
"sync"
"time"
)
type Server struct {
ip string
port string
conn *list.List
mu sync.RWMutex
server *gev.Server
}
func New(ip, port string) (*Server, error) {
var err error
s := new(Server)
s.conn = list.New()
s.server, err = gev.NewServer(s,
gev.Address(ip+":"+port))
if err != nil {
return nil, err
}
s.ip = ip
s.port = port
return s, nil
}
func (s *Server) Start() {
log.Printf("Starting server at %s:%s\n", s.ip, s.port)
s.server.RunEvery(1*time.Second, s.RunPush)
s.server.Start()
}
func (s *Server) Stop() {
s.server.Stop()
}
func (s *Server) RunPush() {
var next *list.Element
s.mu.RLock()
defer s.mu.RUnlock()
for e := s.conn.Front(); e != nil; e = next {
next = e.Next()
c := e.Value.(*connection.Connection)
_ = c.Send([]byte("hello\n"))
}
}
func (s *Server) OnConnect(c *connection.Connection) {
log.Println(" OnConnect : ", c.PeerAddr())
s.mu.Lock()
e := s.conn.PushBack(c)
s.mu.Unlock()
c.SetContext(e)
}
func (s *Server) OnMessage(c *connection.Connection, buffer *ringbuffer.RingBuffer) (out []byte) {
log.Println("OnMessage")
first, end := buffer.PeekAll()
out = first
if len(end) > 0 {
out = append(out, end...)
}
buffer.RetrieveAll()
return
}
func (s *Server) OnClose(c *connection.Connection) {
log.Println("OnClose")
e := c.Context().(*list.Element)
s.mu.Lock()
s.conn.Remove(e)
s.mu.Unlock()
}
func main() {
s, err := New("", "5555")
if err != nil {
panic(err)
}
defer s.Stop()
s.Start()
} go run main.go
2019/10/15 10:49:28 Starting server at :5555
2019/10/15 10:49:50 OnConnect : 127.0.0.1:63521
2019/10/15 10:49:55 OnClose 我这样启动没问题,区别就在于 导入包 "github.com/defsky/gev" 。 你复制我这个代码,再试试。 ps:建议学一下 markdown 的语法,这样贴代码比较容易阅读。 |
就算直接运行 gev/example/pushmessage/main.go,都是这样的
|
你的 go 版本和环境发下,我看看能不能复现。 |
这个?
|
我这边没你这个机器的环境,我看日志觉得还是 timingwheel 库 的问题。 你先试试运行下面这个,会不会 panic : package main
import (
"fmt"
"time"
"github.com/RussellLuo/timingwheel"
)
type EveryScheduler struct {
Interval time.Duration
}
func (s *EveryScheduler) Next(prev time.Time) time.Time {
return prev.Add(s.Interval)
}
func main() {
tw := timingwheel.NewTimingWheel(time.Millisecond, 20)
tw.Start()
defer tw.Stop()
_ = tw.ScheduleFunc(&EveryScheduler{time.Second}, func() {
fmt.Println("The timer fires")
})
select {}
} |
这个也会panic
|
是的, bug 就在这里 timingwheel 库里。 |
是的,centos 7正常,centos 6.5会有这个panic |
我晚上也会再配个环境,找找问题。 |
老哥,可以帮忙再测测吗? 下面的代码,再运行看看,看看会不会 panic : ps:和之前的代码,导入的包地址不通。 package main
import (
"fmt"
"time"
"github.com/Allenxuxu/timingwheel"
)
type EveryScheduler struct {
Interval time.Duration
}
func (s *EveryScheduler) Next(prev time.Time) time.Time {
return prev.Add(s.Interval)
}
func main() {
tw := timingwheel.NewTimingWheel(time.Millisecond, 20)
tw.Start()
defer tw.Stop()
_ = tw.ScheduleFunc(&EveryScheduler{time.Second}, func() {
fmt.Println("The timer fires")
})
select {}
} |
好了。
|
...
TEXT runtime∕internal∕atomic·Xchg64(SB),NOSPLIT,$0-20
--
| // no XCHGQ so use CMPXCHG8B loop
| MOVL ptr+0(FP), BP
| TESTL $7, BP
| JZ 2(PC)
| MOVL 0, AX // crash when unaligned
... 上面最后一行,注释说明了,未对齐会崩溃。 我已经给 RussellLuo/timingwheel PR 了 :RussellLuo/timingwheel#14 |
好的 谢谢! |
我已经提交了代码了:将 RussellLuo/timingwheel 替换成 Allenxuxu/timingwheel 了。 RussellLuo 合并我的代码后,我再切回来,现在你可以正常使用。 感谢帮忙测试🙏 |
RussellLuo 已经合并我的代码,已经切回将 RussellLuo/timingwheel ,可以拉取最新 gev 代码获取。 |
go get 获取到的怎么总是v0.0.2这个版本 是不是还需要发给release才能获取到最新版本呢? |
已经发布 release v0.1.0 |
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x804a6bc]
goroutine 1 [running]:
runtime/internal/atomic.Xchg64(0xa1201ac, 0xc9fda7b8, 0x16d, 0x0, 0x38b)
/usr/lib/golang/src/runtime/internal/atomic/asm_386.s:151 +0xc
github.com/Allenxuxu/timingwheel%2eV2.(*bucket).SetExpiration(...)
/home/gohome/pkg/mod/github.com/!allenxuxu/timingwheel.!v2@v0.0.0-20190920124930-519aff1ed880/bucket.go:74
github.com/Allenxuxu/timingwheel%2eV2.(*TimingWheel).add(0xa0ae0a0, 0xa0ade80, 0xa0ae0a0)
/home/gohome/pkg/mod/github.com/!allenxuxu/timingwheel.!v2@v0.0.0-20190920124930-519aff1ed880/timingwheel.go:79 +0x167
github.com/Allenxuxu/timingwheel%2eV2.(*TimingWheel).add(0xa0ae000, 0xa0ade80, 0xa0adea0)
/home/gohome/pkg/mod/github.com/!allenxuxu/timingwheel.!v2@v0.0.0-20190920124930-519aff1ed880/timingwheel.go:106 +0x1f2
github.com/Allenxuxu/timingwheel%2eV2.(*TimingWheel).addOrRun(0xa0ae000, 0xa0ade80)
/home/gohome/pkg/mod/github.com/!allenxuxu/timingwheel.!v2@v0.0.0-20190920124930-519aff1ed880/timingwheel.go:113 +0x29
github.com/Allenxuxu/timingwheel%2eV2.(*TimingWheel).EveryFunc(0xa0ae000, 0x3b9aca00, 0x0, 0xa0782c0, 0xa07c3a0)
/home/gohome/pkg/mod/github.com/!allenxuxu/timingwheel.!v2@v0.0.0-20190920124930-519aff1ed880/timingwheel.go:185 +0x190
github.com/Allenxuxu/gev.(*Server).RunEvery(...)
/home/gohome/pkg/mod/github.com/!allenxuxu/gev@v0.0.2/server.go:84
main.(*Server).Start(0xa07c3a0)
/home/gohome/pkg/mod/github.com/!allenxuxu/gev@v0.0.2/example/pushmessage/main.go:33 +0x72
main.main()
/home/gohome/pkg/mod/github.com/!allenxuxu/gev@v0.0.2/example/pushmessage/main.go:90 +0x85
exit status 2
系统信息:
Linux develop 2.6.32-358.el6.i686 #1 SMP Thu Feb 21 21:50:49 UTC 2013 i686 i686 i386 GNU/Linux
The text was updated successfully, but these errors were encountered: