Unusable DATA_DIR error names DATA_DIR; report file number is atomic.Int64 (closes #148, closes #161)
check / check (push) Waiting to run
check / check (push) Waiting to run
When the backend runs on its own, a DATA_DIR that could not be created or read stopped the start with an error that named the path but not DATA_DIR, and one where no file could be created let it start, to fail at the first write of a report file. The start now creates a file in DATA_DIR and removes it, and all three cases fail with DATA_DIR "<value>": <reason>, the form config.New uses for the other settings. Tests start the buffer with DATA_DIR below a regular file and with DATA_DIR set to /proc. The report file sequence counter is atomic.Int64 instead of atomic.Uint64, as the Go style guide asks for int types. File names are unchanged. Model: opus-5-5
This commit is contained in:
@@ -88,7 +88,7 @@ type Buffer struct {
|
||||
now func() time.Time
|
||||
// seq numbers the report files, so that two named in the same
|
||||
// millisecond still get different names.
|
||||
seq atomic.Uint64
|
||||
seq atomic.Int64
|
||||
stopOnce sync.Once
|
||||
// usedBytes is what Append checks against maxBytes: the size
|
||||
// of the report files in dataDir, plus the reports waiting to
|
||||
@@ -127,16 +127,33 @@ func New(
|
||||
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(_ context.Context) error {
|
||||
// The errors name DATA_DIR, as config.New's do for the
|
||||
// settings it checks.
|
||||
err := os.MkdirAll(b.dataDir, dirPerms)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create data dir: %w", err)
|
||||
return fmt.Errorf("DATA_DIR %q: %w", b.dataDir, err)
|
||||
}
|
||||
|
||||
// Creating and removing a file stops the start when no
|
||||
// file can be created in DATA_DIR, instead of the first
|
||||
// write of a report file failing after reports were
|
||||
// answered 200. A full disk is not caught: the empty
|
||||
// file is still created.
|
||||
f, err := os.CreateTemp(b.dataDir, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("DATA_DIR %q: %w", b.dataDir, err)
|
||||
}
|
||||
|
||||
err = errors.Join(f.Close(), os.Remove(f.Name()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("DATA_DIR %q: %w", b.dataDir, err)
|
||||
}
|
||||
|
||||
// Report files left by earlier runs count too, and are
|
||||
// the first to be deleted to make room.
|
||||
files, err := reportFiles(b.dataDir)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("DATA_DIR %q: %w", b.dataDir, err)
|
||||
}
|
||||
|
||||
b.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user