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 _writev to only call its callback when all chunks are done #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

laganojunior
Copy link

Fixs github issue #49

This allows stream events such as 'finish' to work correctly on the
transport stream instead of possibly triggering before the individual
log calls have been finished.

Fixs github issue winstonjs#49

This allows stream events such as 'finish' to work correctly on the
transport stream instead of possibly triggering before the individual
log calls have been finished.
@danielweck
Copy link

Interesting approach, thanks for taking the time to submit a PR. Let's hope a suitable fix makes it to Winston in the next point-release. It is a shame to rely on a hack.

@montdidier
Copy link

I would just like to feedback that this PR works for me. It works as intended.

@laganojunior
Copy link
Author

@montdidier Just out of curiosity, what did you test? Did you have some code before that used to break and you used this patch and saw that it didn't afterward?

@montdidier
Copy link

montdidier commented Sep 5, 2019

@laganojunior I have an AWS lambda that logs to papertrail. I kept hitting write after end errors even though I was only exiting the lambda on logger.on('finish', ...). I call logger.end() when the input stream hits it's own finish and then the logger finish always seemed to fire before the logger was actually drained. This problem went away after using this patch/branch.

I am not sure if that is exactly what happened but, short answer, yes, I had existing broken code that this fixed. I was about to abandon winston because it just seems extremely fragile/brittle.

index.js Outdated
@@ -151,18 +167,16 @@ TransportStream.prototype._writev = function _writev(chunks, callback) {

if (errState || !transformed) {
// eslint-disable-next-line callback-return
chunks[i].callback();
wrapCallback(i);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be wrapCallback(i)(), because this code change replaces the chunks[i].callback() function call, not the function reference chunks[i].callback (like the other two instances in this PR).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! This probably didn't come up in the tests because there were no errors. Thanks, I'll fix that up.

@literakl
Copy link

if this patch is correct, why is not it merged? The flushing trouble is very important.

@Hurtak
Copy link

Hurtak commented Aug 3, 2021

Any update?

@indexzero
Copy link
Member

Any idea why CI is failing?

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.

6 participants