defer closing tailable file via subcontext

+ update deps for defer f.Close()
This commit is contained in:
rasmus 2022-11-06 14:41:09 +02:00
parent 4554ddb188
commit 1617658d1a
3 changed files with 7 additions and 3 deletions

View File

@ -117,8 +117,10 @@ func (s *submitter) shipFileRoutine(ctx context.Context, name string, deleteOk f
}
startSize := fi.Size()
// TODO: use inotify for file, and end with file deletion or replacement
lineChan, errChan, err := util.TailFile(ctx, name, log.Offset, io.SeekStart)
sctx, cancel := context.WithCancel(ctx)
defer cancel()
lineChan, errChan, err := util.TailFile(sctx, name, log.Offset, io.SeekStart)
if err != nil {
return fmt.Errorf("tailing file: %w", err)
}

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.19
require (
github.com/fsnotify/fsnotify v1.6.0
github.com/jtagcat/util v0.0.0-20221103213637-071f312fb4b0
github.com/jtagcat/util v0.0.0-20221106123855-f4d34033addb
github.com/prometheus/client_golang v1.13.1
github.com/urfave/cli/v2 v2.23.4
go.elastic.co/ecszap v1.0.1

2
go.sum
View File

@ -155,6 +155,8 @@ github.com/jtagcat/util v0.0.0-20221103102321-5f3517595fd1 h1:7J6mfQWfX/0jkeoaOX
github.com/jtagcat/util v0.0.0-20221103102321-5f3517595fd1/go.mod h1:VIg6NAm5vU1HwDCL8p/iILmCwvgVCP3/U4QhlS6hftY=
github.com/jtagcat/util v0.0.0-20221103213637-071f312fb4b0 h1:XeIjmB047GgFXqDhJR+ZugLtMJaWzYmZYzpTCiyidlE=
github.com/jtagcat/util v0.0.0-20221103213637-071f312fb4b0/go.mod h1:VIg6NAm5vU1HwDCL8p/iILmCwvgVCP3/U4QhlS6hftY=
github.com/jtagcat/util v0.0.0-20221106123855-f4d34033addb h1:D7X3joRJVj/X7LJekb8Rco0QD/RuD/sF/j0pcCWWJas=
github.com/jtagcat/util v0.0.0-20221106123855-f4d34033addb/go.mod h1:VIg6NAm5vU1HwDCL8p/iILmCwvgVCP3/U4QhlS6hftY=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=