-
Notifications
You must be signed in to change notification settings - Fork 6
Description
I have a conceptual problem with lifespan events and PAGI middleware.
This isn't documented, but technically all middleware should forward lifespan events to the wrapped apps, since apps may try to depend on their lifespan hooks being fired before they do actual work. However, some apps may not support lifespan hooks and throw an exception about unsupported scope (as documented in the spec).
Lets say there is a middleware which wraps more than one PAGI application and runs them conditionally. This is in essence what Thunderhorse does. What should it do with lifespan events? I guess fire all apps with the event as received, but that requires a full loop with try/catch to continue passing the event to more apps in case one of them throws unsupported lifespan. However, doesn't this mean that all events will already be emptied in $receive after the first app consumes it?
Or maybe lifespan events are only "extra" and apps should not depend on them being fired? That does not seem like the case, since this is documented:
Lifespan events must be sent by every PAGI server instance or worker that manages an application event loop. This ensures that application-level resources are initialized and cleaned up in the context in which they run.
The problem is that Thunderhorse router may point to any application during the runtime just fine (when the request arrives), but lifespan event is technically directed at all applications in the system, which I find hard to implement. I guess PAGI::App::Router would suffer the same problem, but it silently ignores lifespan events entirely.