-
Notifications
You must be signed in to change notification settings - Fork 33
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
Comments to environment cleanup handlers #18
Comments
Having started this whole thing I feel I should chime in, I really like the proposal, the API is simple and analogous to the existing $env API, and in particular having an existing ArrayRef instead of relying an object garbage collection makes this fast and robust. |
I think that instead of an arrayref, it should be a coderef, e.g. |
@hdp i'd say that sounds too complicated. |
For example,
This isn't particularly pretty code, and I haven't tested it, but it should be enough to show the sort of thing I'd like to make sure we can enable. |
@miyagawa code using it would potentially be complicated, yes. The actual psgix.cleanup.register function does not need to be very complicated, e.g. the implementation in my middleware. |
Understood the intent, but particularly:
There's no guarantee here that the wrapped Also, let's say we want to do this with StackTrace - but the response has already been sent, and there's no place to capture the errors and report to users. So this is not really a valid use case where we can think of. As a bottom line i don't want to update existing middleware to support this - |
@kazuho asks what is the order of the execution of stacked cleanup handlers. It maybe a) FIFO b) LIFO or c) Unspecified. http://twitter.com/kazuho/status/111279294730342400 |
I don't understand why you say there's no guarantee Anyway, this would in no way require existing middleware to be My biggest problem with this is that exposing a plain arrayref is too-tight coupling. It means that you can't write a middleware or server whose 'cleanup' handler forks a new process, or serializes arguments and sends them off to some other server for handling, or does anything other than 'accumulate these in memory until the end of the request'. It also implies that there is a guarantee of ordering, which may make some optimizations impossible. |
In case of Twiggy and Feersum, the streaming callback is registered using timer and such, so the local() will be out of scope when the actual callback runs. |
Because that's the goal of this proposal.
I fail to see why you can't write such middleware. Or are you saying that you can't write multiple of such middleware and combine them each other without side affects? |
You can write them, but they are then stuck with the same semantics as the proposal (everything waits until the end). I guess this is out of the scope you see for this proposal, and I seem to be the only dissenter, so I will stop trying to convince you. |
Same as what? The important thing here is that it won't block browsers/clients, not other registered handlers. In case of mod_perl cleanup handlers, if you register |
One other thing to consider is that e.g. in apache you can call For Plack that would mean that That should probably be added to the spec. |
I think Regarding "Callbacks will be called once a request is complete", what does "complete" mean here? The response stream has been closed? Or when all bytes of the response written to the socket? The later may be useful for Feersum-using apps that want to detect if a response was delivered downstream in its entirety. Is it worth specifing when the ref to each handler is dropped? Two options are "right after each handler executes" and "when the I think it's a good comment about the relative order of In the case of Feersum implementation, what would be better: an "idle" handler or a "next tick" handler (i.e. right after current event handlers fire)? We could make Twiggy use the AnyEvent analogy. For a future spec: If a server supports keep-alives, and there's a PSGI environment var associated with a connection (not a request), specifying a connection cleanup handler in addition to these request cleanup handlers would be good for consistency. |
Hm, that sounds a bit too much detailed, but if it makes sense, that should be added as "psgix.harakiri action SHOULD run after all the cleanup handlers are called" |
Agreed.
I usually make things like that vague enough to mean that it is specific to server implementations.
The latter, "when the
harakiri is usually (only?) useful in the case of preforking server handlers, so if harakiri is to be committed, I'd imagine th server
Makes sense, but that sounds like a different area of interest from this one - at least a bit too specific to non-blocking async implementations :) At the very least, the original idea of "poor man's job processing" doesn't make much sense in the context of non-blocking servers, since running |
I think, at least, it has to mean that the client will not be waiting for the execution of whatever coderefs are in |
+1 |
Thanks for the responses. I'm happy with how it stands. |
What's the current status of the proposal? I.e. what needs to happen for it to be ratified? |
Note that uwsgi has now implemented this: unbit/uwsgi@cf480e4 |
One change I'd like to make to this is that servers s/SHOULD/MUST/ implement cleanup handlers in such a way that cleanup handlers run before the harakiri checker. I think the main reason for doing so is not so that the cleanup handlers can commit the harakiri flag (although that's handy too), but because the cleanup handlers might be doing other important things that should be done before the child is killed, e.g. sending out logging information over the network, executing piled-up database requests etc. If you write an application that relies on that it's a giant PITA to handle the edge case of not being able to kill the child in the same request (e.g. because it ran out of memory). From looking at how a few servers implement these mechanisms I've concluded that there's no good reason why this can't be a MUST instead of SHOULD. |
Add comments to https://github.com/miyagawa/psgi-specs/wiki/Proposal%3A-PSGI-environment-cleanup-handlers
The text was updated successfully, but these errors were encountered: