From cff5600c8abebd1ce988b2185c07e998c4a1d483 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Fri, 23 Jun 2023 23:37:57 +0200 Subject: fix: Wrap media scan into a go routine For some unknown reason `ReadExif` hangs when the context is canceled through signal handling. Perhaps perl-exif tooling is closing on `SIGNINT`. --- pkg/worker/exif_scanner.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'pkg') diff --git a/pkg/worker/exif_scanner.go b/pkg/worker/exif_scanner.go index 6d40dbd..d7865e3 100644 --- a/pkg/worker/exif_scanner.go +++ b/pkg/worker/exif_scanner.go @@ -33,8 +33,33 @@ func (e *EXIFScanner) Query(ctx context.Context) ([]*media.Media, error) { return medias, nil } +func wrapReadExif(ctx context.Context, path string) (*media.MediaEXIF, error) { + c := make(chan *media.MediaEXIF) + e := make(chan error) + go func() { + defer close(c) + defer close(e) + + newExif, err := fileop.ReadExif(path) + if err != nil { + e <- err + } else { + c <- newExif + } + }() + + select { + case <-ctx.Done(): + return nil, ctx.Err() + case m := <-c: + return m, nil + case err := <-e: + return nil, err + } +} + func (e *EXIFScanner) Process(ctx context.Context, m *media.Media) error { - newExif, err := fileop.ReadExif(m.Path) + newExif, err := wrapReadExif(ctx, m.Path) if err != nil { return err } -- cgit v1.2.3