Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add guard clause to prevent FD leak #2301

Merged
merged 2 commits into from
May 18, 2023

Conversation

td-tomasz
Copy link
Contributor

  • Added guard clause to prevent trying to rotate files when there is already ongoing rotation
  • Destroy streams in cleanup method to make sure they are "destroyed"

@td-tomasz
Copy link
Contributor Author

FEI, generally whole issue was introduced in Node v13.0.0 (about 3 and half years ago), most likely by one of stream related changes.
image

@wbt
Copy link
Contributor

wbt commented Apr 26, 2023

I understand this to be an alternative to #2300 and this one also looks pretty good; does anyone else have comments/review?

Thanks @td-tomasz-joniec for the simplified PR!

(Addition of a regression test would be welcome, but I don't see the absence of one as a merge-blocker here.)

@td-krzysiek
Copy link
Contributor

td-krzysiek commented Apr 26, 2023

Thanks, we are looking forward for the update, in one of our applications (edge case) this resulted in entire drive filled up in a few hours.

For me the problematic part was related to the fact that the log function can reach this._stream.write [1] multiple times before logged [2] function is called for the first time (and _rotate flag is set). This results in multiple logged calls which is problematic. Since the code checks _rotate flag in logged function, there is no way that this._endStream(() => this._rotateFile()); is called multiple times.

There was similar attempt in #2115 but I don't think this is correct, the _rotate flag is cleared too early which results in incorrect behaviour of recursive log queuing here:

if (this._rotate) {
this._stream.once('rotate', () => {
this._rotate = false;
this.log(info, callback);
});
return;
}

I hope this helps :)

@td-krzysiek
Copy link
Contributor

Hello,

@wbt any news on this one?

Kind regards,
Krzysztof

@wbt wbt merged commit c198523 into winstonjs:master May 18, 2023
@td-krzysiek
Copy link
Contributor

Great, thank you! Will you be able to npm release too? This will be very helpful.

@wbt
Copy link
Contributor

wbt commented May 26, 2023

Done.

renovate bot referenced this pull request in tsangste/nx-package-test Sep 21, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@swc/helpers](https://swc.rs)
([source](https://github.com/swc-project/swc)) | [`0.5.1` ->
`0.5.2`](https://renovatebot.com/diffs/npm/@swc%2fhelpers/0.5.1/0.5.2) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/@swc%2fhelpers/0.5.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@swc%2fhelpers/0.5.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@swc%2fhelpers/0.5.1/0.5.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@swc%2fhelpers/0.5.1/0.5.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [winston](https://github.com/winstonjs/winston) | [`3.8.2` ->
`3.10.0`](https://renovatebot.com/diffs/npm/winston/3.8.2/3.10.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/winston/3.10.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/winston/3.10.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/winston/3.8.2/3.10.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/winston/3.8.2/3.10.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>swc-project/swc (@&#8203;swc/helpers)</summary>

###
[`v0.5.2`](https://github.com/swc-project/swc/compare/c77f175ace114c12a783b387c42002de1c21ce3a...d15eaf05cd50dc4700d0e2ceeee828bced1a1f74)

[Compare
Source](https://github.com/swc-project/swc/compare/c77f175ace114c12a783b387c42002de1c21ce3a...d15eaf05cd50dc4700d0e2ceeee828bced1a1f74)

</details>

<details>
<summary>winstonjs/winston (winston)</summary>

###
[`v3.10.0`](https://github.com/winstonjs/winston/releases/tag/v3.10.0)

[Compare
Source](https://github.com/winstonjs/winston/compare/v3.9.0...v3.10.0)

- Avoid potential github issues - relax engines node requirement in
package.json
[`fc9c83d`](https://github.com/winstonjs/winston/commit/fc9c83d)
- Export Logger class
([#&#8203;2181](https://github.com/winstonjs/winston/issues/2181))
[`eda40ef`](https://github.com/winstonjs/winston/commit/eda40ef)
- Added Lazy option to file transport
([#&#8203;2317](https://github.com/winstonjs/winston/issues/2317))
[`f7e7f2f`](https://github.com/winstonjs/winston/commit/f7e7f2f)
- Bump eslint from 8.32.0 to 8.44.0
([#&#8203;2321](https://github.com/winstonjs/winston/issues/2321))
[`de2e887`](https://github.com/winstonjs/winston/commit/de2e887)
-
docs([#&#8203;2319](https://github.com/winstonjs/winston/issues/2319)):
Syntax error on README.md
([#&#8203;2320](https://github.com/winstonjs/winston/issues/2320))
[`fcc69ec`](https://github.com/winstonjs/winston/commit/fcc69ec)
- fix(types): Allow any object to be passed as meta to logger.profile
([#&#8203;2314](https://github.com/winstonjs/winston/issues/2314))
[`9d6001a`](https://github.com/winstonjs/winston/commit/9d6001a)
- Bump [@&#8203;types/node](https://github.com/types/node) from
18.11.18 to 20.3.1
([#&#8203;2313](https://github.com/winstonjs/winston/issues/2313))
[`06e3165`](https://github.com/winstonjs/winston/commit/06e3165)
- Update supported Node versions and run npm audit fix
([#&#8203;2315](https://github.com/winstonjs/winston/issues/2315))
[`61e2f5b`](https://github.com/winstonjs/winston/commit/61e2f5b)
- Bump [@&#8203;babel/core](https://github.com/babel/core) from
7.20.12 to 7.22.1
([#&#8203;2309](https://github.com/winstonjs/winston/issues/2309))
[`7643ad6`](https://github.com/winstonjs/winston/commit/7643ad6)

###
[`v3.9.0`](https://github.com/winstonjs/winston/blob/HEAD/CHANGELOG.md#v390)

[Compare
Source](https://github.com/winstonjs/winston/compare/v3.8.2...v3.9.0)

##### Functionality changes

- Handle undefined errors in getAllInfo in exception-handler in
[https://github.com/winstonjs/winston/pull/2208](https://github.com/winstonjs/winston/pull/2208);
thanks to new contributor
[@&#8203;eivindrs](https://github.com/eivindrs)
- fix: properly allow passing non-array transport in
[https://github.com/winstonjs/winston/pull/2256](https://github.com/winstonjs/winston/pull/2256);
thanks to new contributor [@&#8203;Tanuel](https://github.com/Tanuel)
- fix [#&#8203;1732](https://github.com/winstonjs/winston/issues/1732)
(Http Transport uses JSON format options as request options) in
[https://github.com/winstonjs/winston/pull/2272](https://github.com/winstonjs/winston/pull/2272);
thanks to new contributor
[@&#8203;MoritzLoewenstein](https://github.com/MoritzLoewenstein)
(minor version bump per comment on the issue)
- fix: add guard clause to prevent FD leak in
[https://github.com/winstonjs/winston/pull/2301](https://github.com/winstonjs/winston/pull/2301);
thanks to new contributor
[@&#8203;td-tomasz-joniec](https://github.com/td-tomasz-joniec)

##### Dependency updates by
[@&#8203;dependabot](https://github.com/dependabot) + CI autotesting

- Bump eslint from 8.23.0 to 8.32.0 by
[@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/winstonjs/winston/pull/2209](https://github.com/winstonjs/winston/pull/2209),
[https://github.com/winstonjs/winston/pull/2236](https://github.com/winstonjs/winston/pull/2236),
[https://github.com/winstonjs/winston/pull/2258](https://github.com/winstonjs/winston/pull/2258),
&
[https://github.com/winstonjs/winston/pull/2271](https://github.com/winstonjs/winston/pull/2271)
- Bump [@&#8203;babel/core](https://github.com/babel/core) from 7.19.0
to 7.20.12 by [@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/winstonjs/winston/pull/2206](https://github.com/winstonjs/winston/pull/2206),
[https://github.com/winstonjs/winston/pull/2234](https://github.com/winstonjs/winston/pull/2234),
[https://github.com/winstonjs/winston/pull/2259](https://github.com/winstonjs/winston/pull/2259),
&
[https://github.com/winstonjs/winston/pull/2275](https://github.com/winstonjs/winston/pull/2275)
- Bump [@&#8203;types/node](https://github.com/types/node) from 18.0.0
to 18.11.18 by [@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/winstonjs/winston/pull/2215](https://github.com/winstonjs/winston/pull/2215),
[https://github.com/winstonjs/winston/pull/2235](https://github.com/winstonjs/winston/pull/2235),
&
[https://github.com/winstonjs/winston/pull/2264](https://github.com/winstonjs/winston/pull/2264)
- Bump [@&#8203;babel/preset-env](https://github.com/babel/preset-env)
from 7.19.0 to 7.20.2 by
[@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/winstonjs/winston/pull/2218](https://github.com/winstonjs/winston/pull/2218)
&
[https://github.com/winstonjs/winston/pull/2244](https://github.com/winstonjs/winston/pull/2244)
- Bump safe-stable-stringify from 2.3.1 to 2.4.3 by
[@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/winstonjs/winston/pull/2217](https://github.com/winstonjs/winston/pull/2217)
&
[https://github.com/winstonjs/winston/pull/2292](https://github.com/winstonjs/winston/pull/2292)
- Bump [@&#8203;babel/cli](https://github.com/babel/cli) from 7.18.10
to 7.19.3 by [@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/winstonjs/winston/pull/2216](https://github.com/winstonjs/winston/pull/2216)
- Bump json5 from 2.2.1 to 2.2.3 by
[@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/winstonjs/winston/pull/2260](https://github.com/winstonjs/winston/pull/2260)

##### Documentation changes

- Fix readme typo in
[https://github.com/winstonjs/winston/pull/2230](https://github.com/winstonjs/winston/pull/2230);
thanks to new contributor
[@&#8203;aretecode](https://github.com/aretecode)
- create new example for ready to use in
[https://github.com/winstonjs/winston/pull/2240](https://github.com/winstonjs/winston/pull/2240);
thanks to new contributor
[@&#8203;myagizmaktav](https://github.com/myagizmaktav)
-   minor fixes to publishing.md

##### Build Infrastructure changes

- GitHub Workflows security hardening in
[https://github.com/winstonjs/winston/pull/2252](https://github.com/winstonjs/winston/pull/2252);
thanks to new contributor
[@&#8203;sashashura](https://github.com/sashashura)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://github.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/tsangste/nx-package-test).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi45Ny4xIiwidXBkYXRlZEluVmVyIjoiMzYuOTcuMSIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AifQ==-->

---------

Co-authored-by: Steven Tsang <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants