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: prevent chain effects in pushes #11

Merged
merged 1 commit into from
Apr 17, 2018
Merged

fix: prevent chain effects in pushes #11

merged 1 commit into from
Apr 17, 2018

Conversation

jinwoo
Copy link
Member

@jinwoo jinwoo commented Apr 17, 2018

Fixes google/node-fastify-auto-push#23.

When recording the request patterns, don't use a path as a push key when
it is also included in a push list for another key. It may cause a chain
effect, causing unnecessary pushes. And it seems to crash the server
sometimes.

And also attach an error handler to the push stream.

Fixes google/node-fastify-auto-push#23.

When recording the request patterns, don't use a path as a push key when
it is also included in a push list for another key. It may cause a chain
effect, causing unnecessary pushes. And it seems to crash the server
sometimes.

And also attach an error handler to the push stream.
@jinwoo jinwoo requested review from ofrobots and a team April 17, 2018 19:29
@codecov-io
Copy link

Codecov Report

Merging #11 into master will decrease coverage by 2.37%.
The diff coverage is 69.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #11      +/-   ##
==========================================
- Coverage   92.74%   90.37%   -2.38%     
==========================================
  Files           3        3              
  Lines         124      135      +11     
  Branches       24       24              
==========================================
+ Hits          115      122       +7     
- Misses          9       13       +4
Impacted Files Coverage Δ
ts/src/asset-cache.ts 95.55% <100%> (+0.31%) ⬆️
ts/src/index.ts 84.05% <55.55%> (-4.47%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc35c39...b3cf8f8. Read the comment docs.

@jinwoo
Copy link
Member Author

jinwoo commented Apr 17, 2018

/cc @mcollina

});
};
const onError = (err: Error) => {
console.error('push stream error for:', asset, err);
Copy link

Choose a reason for hiding this comment

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

Spurious console.error?

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to leave some logs when an error occurs during push. Do you think it should use some logging framework?

Choose a reason for hiding this comment

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

this library should either emit an event 'pushError' or accept an option that will be called when this (and maybe other events) happen. fastify has its own logging thing included, see req.log

Copy link
Member Author

Choose a reason for hiding this comment

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

'pushError' sounds good. I'll add that in a separate PR. Will also change the logging with fastify's logging thing. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, sorry I was confused. This is a common package for auto-push, not specific to fastify. So it can't use fastify's logging.

I'll just add pushError.

Choose a reason for hiding this comment

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

Yeah, this should emit pushError, and you should listen to the event in the fastify plugin and log it. You might want to emit the error on the parent stream maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

pushStream is hidden from the client code so it doesn't make sense to emit pushError on pushStream. I'll emit it on the parent stream.

@jinwoo jinwoo merged commit c06a5c5 into google:master Apr 17, 2018
@jinwoo jinwoo deleted the fix branch April 17, 2018 21:41
reject(err);
};
pushStream.once('error', onError);
pushStream.once('finish', onFinish);

Choose a reason for hiding this comment

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

I'm not 100% sure 'finish' is emitted when using respondWithFile  cc @jasnell.

Copy link
Member Author

Choose a reason for hiding this comment

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

I verified that onFinish is called. Otherwise this code wouldn't work because that is the only place where the promise is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants