abiosoft / abiosoft/ishell

History file handle leak

Đang mở
#113 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Go
Star
1.8k
Fork
213
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

The history file is not closed when it is reset, resulting in leaked file handles.

Here's a program that demonstrates the bug:
```
package main

import "gopkg.in/abiosoft/ishell.v2"

func main() {
shell := ishell.New()

shell.AddCmd(&ishell.Cmd{
Name: "on",
Func: func(ctx *ishell.Context) {
shell.SetHistoryPath("test-history")
},
})
shell.AddCmd(&ishell.Cmd{
Name: "off",
Func: func(ctx *ishell.Context) {
shell.SetHistoryPath("")
},
})

shell.Run()
}
```

By watching the output of `lsof -c main` on *nix can see that every call to `on` leaves the previous history file handle open. `off` does not close the existing file handle either.

It seems you need something like:
```
diff --git a/ishell.go b/ishell.go
index 098af06..c0545c1 100644
--- a/ishell.go
+++ b/ishell.go
@@ -393,6 +393,7 @@ func (s *Shell) SetHistoryPath(path string) {
// Instance.
config := s.reader.scanner.Config.Clone()
config.HistoryFile = path
+ s.reader.scanner.Close()
s.reader.scanner, _ = readline.NewEx(config)
}
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.