**加了段代码后,程序跑个两三天就挂一次**
在原有的代码中加了一段如下的功能:
1 遍历文件夹,获取以“no_”命名开头的文件。
2 根据获取的结果做其他操作----------( SetLevel(curLevel) )
下面是代码的主题
var curLevel int
levelCheck := func(logPath string) {
if logPath == "" {
return
}
for {
time.Sleep(time.Second * 30)
s, err := ListLevelKeys(logPath)
if err != nil {
continue
}
level := GetMaxLevel(s)
if curLevel != level {
curLevel = level
log.GetLog().SetLevel(curLevel) //一般情况下不会执行
}
}
}
go levelCheck(s.logDir)
加上之后的程序会异常结束,结束的时候没有panic。也没有coredump文件
*****
附上其他函数完整的定义:
func ListLevelKeys(dirPth string) (files []string, err error) {
if dirPth == "" {
return nil, errors.New("dirPht is null")
}
dir, err := ioutil.ReadDir(dirPth)
if err != nil {
return nil, err
}
for _, fi := range dir {
if fi.IsDir() {
continue
}
filename := fi.Name()
if len(filename) < 3 {
continue
}
if filename[:3] == "no_" {
files = append(files, filename)
}
}
return files, nil
}
func GetMaxLevel(keys []string) (maxlevel int) {
if keys == nil {
return 0
}
GetLevel := func(key string) (level int) {
if len(key) < 3 {
return
}
switch key {
case "no_debug":
level = log.DebugLevel + 1
case "no_info":
level = log.InfoLevel + 1
case "no_warn":
level = log.WarnLevel + 1
case "no_err":
level = log.ErrorLevel + 1
case "no_fatal":
level = log.FatalLevel + 1
case "no_read":
level = log.ReadLevel + 1
case "no_write":
level = log.UpdateLevel + 1
}
return
}
for _, key := range keys {
level := GetLevel(key)
if level > maxlevel {
maxlevel = level
}
}
return
}
log.GetLog().SetLevel(curLevel){
//......
//这个函数之后dir下的"no_*"文件有变动时才会执行,应该不会引起程序异常结束吧?
//一般是不会执行的
}
我找到一个coredump文件。core文件说是Segmentation fault.
我打印了堆栈 没看出具体什么问题。
部分展示如下:
[New LWP 56173]
[New LWP 56178]
[New LWP 56174]
[New LWP 53018]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./cmd -c ds_node.cfg'.
Program terminated with signal 11, Segmentation fault.
#0 0x00000000004427ee in runtime.sigtrampgo (sig=11, info=0xc821725bb0, ctx=0xc821725a80) at /usr/local/go/src/runtime/signal_linux.go:20
20 /usr/local/go/src/runtime/signal_linux.go: No such file or directory.
Missing separate debuginfos, use: debuginfo-install glibc-2.17-78.el7.x86_64
(gdb)
(gdb)
(gdb) bt
#0 0x00000000004427ee in runtime.sigtrampgo (sig=11, info=0xc821725bb0, ctx=0xc821725a80) at /usr/local/go/src/runtime/signal_linux.go:20
#1 0x0000000000461b8b in runtime.sigtramp () at /usr/local/go/src/runtime/sys_linux_amd64.s:234
#2 0x0000000000461b90 in runtime.sigtramp () at /usr/local/go/src/runtime/sys_linux_amd64.s:235
#3 0x0000000000000001 in ?? ()
#4 0x0000000000000000 in ?? ()
(gdb)
#2
更多评论
我找到了一个core文件。内容如下。查看堆栈也没看到具体原因,上面回的乱了,贴上图吧。 ![TimLine图片20160819213646.png](http://studygolang.qiniudn.com/160819/53c0efa60f24cc404c84b013c2f35fcb.png)
#3