1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

fixed closed channel issue, and tail timeout ctx

This commit is contained in:
postmannen 2021-04-16 23:58:43 +02:00
parent 2877bf3a58
commit 3859ae6b9b
2 changed files with 16 additions and 6 deletions

View file

@ -3,10 +3,10 @@
"directory": "./mine-tail-filer/",
"fileExtension": ".log",
"toNode": "ship2",
"data": ["./test.log"],
"data": ["/var/log/system.log"],
"method":"REQTailFile",
"ACKTimeout":5,
"retries":3,
"methodTimeout": 200
"methodTimeout": 10
}
]

View file

@ -900,10 +900,20 @@ func (m methodREQTailFile) handler(proc process, message Message, node string) (
go func() {
fp := message.Data[0]
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(message.MethodTimeout))
var ctx context.Context
var cancel context.CancelFunc
if message.MethodTimeout != 0 {
ctx, cancel = context.WithTimeout(context.Background(), time.Second*time.Duration(message.MethodTimeout))
} else {
ctx, cancel = context.WithCancel(context.Background())
}
outCh := make(chan []byte)
t, err := tail.TailFile(fp, tail.Config{Follow: true})
t, err := tail.TailFile(fp, tail.Config{Follow: true, Location: &tail.SeekInfo{
Offset: 0,
Whence: os.SEEK_END,
}})
if err != nil {
er := fmt.Errorf("error: tailFile: %v", err)
log.Printf("%v\n", er)
@ -922,8 +932,8 @@ func (m methodREQTailFile) handler(proc process, message Message, node string) (
cancel()
// Close the lines channel so we exit the reading lines
// go routine.
close(t.Lines)
er := fmt.Errorf("error: method timed out %v", message)
// close(t.Lines)
er := fmt.Errorf("info: method timeout reached, canceling: %v", message)
sendErrorLogMessage(proc.toRingbufferCh, proc.node, er)
return
case out := <-outCh: