mirror of
https://github.com/syncthing/syncthing.git
synced 2026-10-29 22:48:40 -04:00
### Purpose #10726 introduces a problematic side effect which only surfaced recently in #10882: On Windows 24H2 stdout will be invalid when Syncthing is started detached from a console. This caused the monitors logwriter to fail silently before it writes it a log file. This PR fixes this by letting the multiwriter continue even after failing on stdout. ### Testing #10882 can be reproduced without this PRs commit. With this PR logging does work again. Following scenarios are tested in which the logfile will be written again -console: syncthing.exe -console: start "" syncthing.exe -console: start "" syncthing.exe serve --log-file=path -explorer: double click `go test ./lib/osutil ` checks if the introduced tolerantMultiWriter writes to all targets even on errors. --------- Signed-off-by: Elias <1elias.bauer@gmail.com> Co-authored-by: Elias <1elias.bauer@gmail.com>
35 lines
761 B
Go
35 lines
761 B
Go
// Copyright (C) 2026 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package osutil
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
)
|
|
|
|
// TolerantMultiWriter writes to all of its writers, like io.MultiWriter,
|
|
// except that a failing write to one writer does not prevent writing to the
|
|
// others.
|
|
type TolerantMultiWriter []io.Writer
|
|
|
|
func (t TolerantMultiWriter) Write(p []byte) (int, error) {
|
|
n := 0
|
|
var errs []error
|
|
|
|
for _, w := range t {
|
|
written, err := w.Write(p)
|
|
if written > n {
|
|
n = written
|
|
}
|
|
if err != nil {
|
|
errs = append(errs, err)
|
|
}
|
|
}
|
|
|
|
return n, errors.Join(errs...)
|
|
}
|