Skip to content

Commit 67aace0

Browse files
committed
do not truncate log files on each LogWriter calls
We used to have a single concurrent usage of the `LogWriter`, but this is not the case anymore since b29665f. Because of this we now loose the runner logs as he file is being truncated during the `buildCmd` call when the LogWrited is fetched. To fix this i propose to instantiate the LogWriter once which will effectively truncate the file only once per `server:start` launch.
1 parent 3d44daa commit 67aace0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

local/pid/pidfile.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type PidFile struct {
4949
CustomName string `json:"name"`
5050

5151
path string
52+
lw io.WriteCloser // log writer, used to write logs to the log file
5253
}
5354

5455
func New(dir string, args []string) *PidFile {
@@ -258,15 +259,24 @@ func (p *PidFile) LogReader() (io.ReadCloser, error) {
258259
}
259260

260261
func (p *PidFile) LogWriter() (io.WriteCloser, error) {
262+
// instantiate the log writer only once per process lifetime, this is useful
263+
// to have a single truncate (and thus a clean log file) at the beginning of
264+
// the process management but not truncate the log file when the process is
265+
// restarted.
266+
if p.lw != nil {
267+
return p.lw, nil
268+
}
269+
261270
logFile := p.LogFile()
262-
if err := os.MkdirAll(filepath.Dir(logFile), 0755); err != nil {
271+
err := os.MkdirAll(filepath.Dir(logFile), 0755)
272+
if err != nil {
263273
return nil, err
264274
}
265-
w, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
275+
p.lw, err = os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
266276
if err != nil {
267277
return nil, err
268278
}
269-
return w, nil
279+
return p.lw, nil
270280
}
271281

272282
func (p *PidFile) Binary() string {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy