Skip to content

file description close failed cause fd leak #223

@wangyanphp

Description

@wangyanphp

I noticed that when we call wrirte function, we will run code: https://github.com/natefinch/lumberjack/blob/v2.0/lumberjack.go#L135

when it need to run rotate, it will call file close. from the code of close(), it will only close file once. l.file will be nil whether the file closed success or not.

// close closes the file if it is open.
func (l *Logger) close() error {
	if l.file == nil {
		return nil
	}
	**err := l.file.Close()**
	l.file = nil
	return err
}

So if file.Close() return error, the process will have no chance to release this fd. when we try to write file, the code will be exectuted which will create a new file:

	if l.file == nil {
		if err = l.openExistingOrNew(len(p)); err != nil {
			return 0, err
		}
	}

there is a online case:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions