-
Notifications
You must be signed in to change notification settings - Fork 831
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
Service worker stuck in busy state when SSE request hits the cache #2692
Comments
Hello @andyrichardson! I am not sure that your diagnosis of what's going on is accurate. Calling
Calling
If you're trying to debug why a service worker is waiting in the |
Hey @jeffposnick, thanks for the response.
Totally with you on this - even without checking the spec, I was under a similar assumption that I've managed to consistently reproduce this issue on Chrome and Firefox and the one line change in the PR fixed the problem. I'm not totally sure why this would be the case. I'll spend some time this week creating a reproduction so you can try it out for yourself! Just to confirm, have you tried creating a service worker which calls |
Before you spend too much more time debugging this, can you try a quick swap from using The previous implement of |
I had tried calling self.skipWaiting:
But no dice! The current project I'm on uses whatever is bundled with CRA but I'll try a standalone example without CRA and see if this is still a concern. |
That's very strange. What happens if you go to Chrome's DevTools and manually click on the "skipWaiting" link that you should see next to the waiting service worker? |
Manually clicking I got around to creating a simple reproduction (with v5 and v6 package versions) but I'm unable to reproduce the issue in a more basic environment so I'm not sure what the cause is. If I'm not mistaken, this nesting implies that the service worker has spawned a worker thread - that might be what is keeping the service worker from unloading. That spawned worker thread looks to have some relation to buffering |
JeeeeeezzzOkay I found the cause of the issue. registerRoute(
({ url }) => /^somefeatureflagservice/.test(url.host),
new StaleWhileRevalidate({
cacheName: `flags`,
}),
); In my case, I was caching a feature flagging network request for offline support. This request was a I guess that explains why adding
|
Is workbox's cache intended to work with SSE/websocket/streaming connections? If not, do we want to add in a warning / skip the cache altogether so we don't keep a fetch event open indefinitely? |
Ah, okay, glad that there's an explanation! Service workers don't intercept WebSocket requests, but they can be used with the Streams API, and they also explicitly do intercept SSE, as per this thread that @wanderview participated in back in the day. That thread discussed potential edge cases and had an overall consensus that using service workers with SSE was likely to be uncommon. I'm not ruling out making a change to Workbox if needed, but I'm wondering if there's an underlying issue that would better be addressed by the browser(s). You mentioned both Chrome and Firefox exhibited that behavior—how about Safari? I'd like to summarize the issue and then pull in some folks for their opinion. Please correct me if I'm wrong about any of this:
|
I would expect the service worker to be killed after 5 minutes of being held open by respondWith() processing an SSE response. (Unless another FetchEvent or something occurred since then of course...) Note, if you open devtools then chrome will not terminate the service worker due to this timeout. |
Thanks, @wanderview. Any thoughts on those final two points, where adding in an explicit |
Doesn't make sense from the browser perspective. I don't really know what workbox is doing around where it calls those, though. Maybe its an incorrect association and the real issue was whether devtools had been opened or not, etc. |
Gotcha. If the browser technically shouldn't require that explicit @andyrichardson, what if we added additional logging that's enabled in the I'll wait to hear back from you, but my understanding is that you didn't actually want to have the service worker intercept that SSE, and it's not clear how a |
Hey folks! Thanks for the discussion on this!
Yes that's pretty much it registerRoute(
({ url }) => /^somefeatureflagservice/.test(url.host),
new StaleWhileRevalidate({
cacheName: `flags`,
}),
);
In my case, I wasn't even aware that SSE was present on the app - that request was being made by a third party library. I think the sketchy part here is that once we get into that SEE w/ workbox caching state - it's impossible to push a new service-worker (or app in the case of precaching) and you're at the mercy of when the user exits their browser session. If it's possible to prevent that locked-in condition whether that be by ignoring If not, maybe documentation on filtering out text/event-stream be the second best option. Side note - CRA for better or for worse only enables service workers in production builds. Obviously there's more to web dev than just CRA but it's worth noting that a lot of users could encounter this issue and not be aware until it hits production. |
Hi there, Workbox is moving to a new engineering team within Google. As part of this move, we're declaring a partial bug bankruptcy to allow the new team to start fresh. We realize this isn't optimal, but realistically, this is the only way we see it working. For transparency, here're the criteria we applied:
Thanks, and we hope for your understanding! |
Library Affected:
workbox-routing
Browser & Platform:
all browsers
Issue or Feature Request Description:
Bug report:
Consider the following service worker
When a new service worker exists and installation of the newer worker begins, it would be expected that the use of
skipWaiting
would activate the new service worker.This isn't the case however because the registerRoute function instantiates a fetch handler that never calls waitUntil.
The result of this is that the updated service worker will never activate (stuck in
installed
state) until the user's browser session is closed.The text was updated successfully, but these errors were encountered: