-
Notifications
You must be signed in to change notification settings - Fork 313
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
should update() during top level script evaluation be ignored? #800
Comments
@mattto, can you clarify exactly what chrome does in this case? Does it truly ignore it silently or does it reject with an InvalidStateError? |
Let me take a look. As a process note, I'm having trouble staying on top of Github mail. Is it possible to assign me to these issues that are blocked on my feedback, so I can use the Github's issue tracker to keep track of my tasks? |
Ah, I see searching issues for mentions:matto is a pretty good way. |
Ah you mentioned the wrong matto. I'm @mattto with three t's. |
Ah, sorry! Fixed in the comment above. |
I think it makes more sense to reject the promise. Ignoring it silently seems wrong to me. |
Looks like we reject with a InvalidStateError. The spec probably needs to be revised? In update(), Get Newest Worker is not necessarily null, if there's an active or waiting worker. Then in 9.2 Update, the installing version would be terminated. |
I don't see any problem with the current text. If the install event fails, the worker will get redundant. Rejecting the promise ( |
That's right. And even in the example in the OP, update() was called within the installing worker's script, the newest worker, the installing worker itself, is always there. But the Schedule Job will aggregate this update() job in favor of the running installation, so there won't be such an endless set of failing updates. |
You will still end up with continuous updates running once every 1 second (or whatever update delay the particular browser uses). This seems bad to me. I think we should remove the potential for infinite loops in job scheduling where possible. I think it would be better to silently resolve the update() promise with success if called:
In both cases we can argue an update is already in progress and its the same kind of short-circuit as Register does in its step 5.3. |
I'm not following this. Assuming the browser has an active worker that contains only
Sure, you're going to get a fetch for your SW pretty frequently, but this isn't much worse than putting |
This is missing the part about failing the install. The script in question is more like:
AFAICT this will update continuously until the script is changed. I don't think we should let update() function in a SW that has not reached the installed state. |
@wanderview, I wonder if you considered this point? So, I mean the job created by |
A note on Chrome's implementation: the comment in the Blink's test is misleading: Chrome actually can perform update() during initial script evaluation. It only |
@jungkees Where does it do the aggregation now? I seem to remember we only aggregate SoftUpdates, not explicit update() calls. Also, I can't find the steps that do the aggregation since the change to a single job queue. I'm not sure rejecting if newest worker is null is adequate. The install algorithm sets .installing before executing Run Service Worker. So .installing will be set at top level script evaluation. I think we should probably reject if the only worker is installing with no waiting or active workers. |
The single job queue change made all the equivalent jobs (i.e. jobs from register(), update(), Soft Update) be aggregated in the Schedule Job algorithm step 2.2. |
F2F resolution: @wanderview to review and see if no longer an issue. |
By ccfa7e4,
is not true any more. An equivalent job in the front of the queue whose promise has already settled makes the job passed to Schedule Job be queued. So, more thought and discussion are needed for the issue in this tread. |
I think the easiest way to handle this would be to do something like this in ServiceWorkerRegistration.update():
Would something like that work? |
Agreed on rejecting the update attempt for an installing worker. I think the suggested algorithm steps are good (with a relevant settings object instead of an entry settings object). @matto, WDYT? |
SGTM. |
I put it in the Update algorithm after a thought. I think the consensus is making the |
Sorry, but I don't think the check can be done in the Update algorithm. With it written that way the check won't be executed until after the current job completes and the Update job begins. This means you will never see a worker in the installing state. I think we have to do this check in the update() function itself. Also, I think it should use the service worker associated with its global since this is really only a problem for a service worker updating itself. |
Absolutely. I'll get it done again as you originally suggested. Thanks! |
Addressed: afae5de |
The wpt tests we imported from blink has this code at the top level of one of its service worker scripts:
I don't see anything in the spec that does this. It seems like it might be a good idea, though, to avoid potential infinite async update loops. For example, if the install event fails or something I think you could end up with an endless set of failing update jobs running in the background.
The text was updated successfully, but these errors were encountered: