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
Deglobal #59
Merged
Merged
Deglobal #59
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It's still used in HttpErrorHelper, but I'll need to nix that one, too.
😢 |
}; | ||
|
||
Context.prototype.protocol = function () { | ||
return config.presented_url_proto() || this._request.protocol; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a leftover reference to the _request
property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good catch.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stashing the "current" request and response as globals in
RequestHelper
andResponseHelper
is not a good idea. It works... as long a single presenter is never serving more than one request at once, in which case you'll very quickly start writing output to the wrong response object. I believe this is the cause of the sporadic "headers already sent" bug that we've been seeing this month (and now that I have some basic log aggregation going, I'm seeing the occasional 500 be served in production).Essentially, this is a consequence of the way that node.js does asynchronous I/O with its event loop. Even though node is single-process and single-threaded, it achieves the throughput it does by interleaving other work while one request's handler is blocked waiting for upstream I/O to complete. This means that, while request A is waiting for a response from the content service, a request B that arrives before that response does will begin to be handled, and trash
ResponseHelper._response
for request A before request A has a chance to be completed.I rigged up a simple demonstration of this happening by assigning IDs to each response object and firing a bunch of curl requests. Notice how every request tries to complete by writing to response 5, not its actual response object!
In its place, I've replaced the global service state with a
Context
object that knows the current request and response and can mediate some of the mechanics that were being handled by theRequestHelper
andResponseHelper
methods, as well as theHttpErrorHelper
.