-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Spec ambiguity: environment instance #2144
Comments
The I think 3 is closest to how it works today, however you are correct, whether the information can bubble up is not specified. Is there value in specifying it? |
Seems unlikely the intention has ever been 1.? Seeing rack itself ships with the Lines 12 to 22 in 3897649
|
@dentarg this example only passes down the Rack stack. The question is whether we can rely on
Or if the only reliable way is via the return value (which is limited in what it allows + can be mutated willy nilly by each middleware), in which case we have to resort to things like this:
|
I believe there is:
I'm fine either way, as long as this is clarified. |
Fair point regarding this in case 1.:
Note that in case 1. I added this about the values being immutable only as an possibility ("this may be complemented by"), but what would matter much more is the In the spec things like |
@ioquatix Looking into hijack (which I must admit I've never used) I found this bit of yours:
This seems to exclude 2. as the possibility of In practice too, 1. is not realistic today, as To the best of my knowledge, Both In addition the Partial Hijack section describes an alternative way to bubble up information:
This gives additional credence to the rationale that Therefore the only possible practical state of the Rack 3.0 spec is 3: Any of this may or may not change in the future, but that would be a breaking change and thus a Rack 4 spec. |
@ioquatix given the amount of digging I had to do and the possibility of subtle breakage I definitely think there is value in specifying it, even if it's only a few words. |
I don't think we should specify behavior here. While we could say that reusing |
Agree; the spec does not enumerate things you can't assume, and beginning to do so only moves towards people feeling more free to assume anything that hasn't been explicitly excluded. The nature of any spec of this sort is that it is very explicit about a small set of things you can rely upon, and anything else is definitionally not guaranteed. |
I would support the addition of a document that outlines best practices such as discussed here. In some ways the upgrade guide I wrote tried to encapsulate some of that knowledge, but specific to Rack 2 -> Rack 3 changes. I think it's expected that env goes down the stack and the result goes up. In other words, I don't see that as surprising. However, while we do want to encourage this model, it's not a hard line drawn by the specification, in other words, there are cases where other approaches can work. As an example, |
Okay I think I get the idea: the Rack spec is largely unconcerned with what people do with the Rack middleware stack, it merely specifies that the Rack stack and the web server can communicate using the protocol. IIUC then a system or framework could build its Rack stack based on any of these approaches:
Of course some of these options would be mutually exclusive but it's up to the Rack stack builder to make sure that they only use those that are not. tl;dr: Fine by me, this is now all clear enough. Thank you all! |
The spec says this regarding the environment instance:
But it does not say whether through the Rack stack the environment may or may not be
dup
'd to be passed to the next call.Specifically these cases could be specified:
The environment instance MUST NOT be the same across calls through the stack: this would ensure that information is forgotten at each step when bubbling up the Rack stack, providing isolation from lower levels to upper levels, at least for the environment hash itself, but not for the values themselves. This may be complemented by:
The benefit would be to assume functional style side-effect-freeness from the environment within a given middleware level. Annotated example:
The environment instance MUST be the same across calls through the stack. Mutation of existing values attached to environment keys or value instances themselves is allowed and MUST NOT be prevented.
The benefit would be to ensure that information is kept when unwinding the Rack stack, providing a mechanism to bubble information to the upper levels. Annotated example:
The environment instance MAY OR MAY NOT be the same across calls through the stack: this means the environment can be relied on when going down the Rack stack but CANNOT be relied on when unwinding, thus SHALL NOT be used to bubble up information when the Rack stack unwinds.
The benefit is that it's a free for all, whoever wants to do anything can, but the consequence of that must be made very clear, no middleware can assume anything about what's going up above or below, including unanticipated whatever unanticipated middlewares might do.
Currently:
WDYT? Is Rack's design intended to be 1., 2., or 3.?
The text was updated successfully, but these errors were encountered: