servo icon indicating copy to clipboard operation
servo copied to clipboard

Create send_request macro for WebGPURequest

Open Taym95 opened this issue 1 year ago • 12 comments


  • [x] ./mach build -d does not report any errors
  • [x] ./mach test-tidy does not report any errors
  • [x] These changes fix #32488
  • [x] These changes do not require tests because there is no behavior change

Taym95 avatar Jun 14 '24 13:06 Taym95

I think we can generalize this a bit more (adding optional custom error message using format syntax) and move it to ipc channel as similar pattern is everywhere not just in webgpu.

But firstly let's get some consensus on this. cc @mrobinson @wusyong @gterzian

sagudev avatar Jun 14 '24 15:06 sagudev

I suspect that different modules will want to handle IPC failures in different ways. For instance in the case of WebGPU, it will likely need to shut down the task and return. On the other hand , the Constellation would probably want to restart the failed tasks.

mrobinson avatar Jun 14 '24 15:06 mrobinson

I suspect that different modules will want to handle IPC failures in different ways. For instance in the case of WebGPU, it will likely need to shut down the task and return. On the other hand , the Constellation would probably want to restart the failed tasks.

In that cases when error is actually handled we would not use macro, but do manual handling. Macro would only serves as a shorter way to write send and warn on error:

if let Err(e) = sender.send(Msg) {
    error!("Failed to send Msg due to error: {e}");
   // nothing else here
}

Or are you suggesting that we should actually replace all such patterns with actual error handling not just logging, so why bother with making it easier.

sagudev avatar Jun 14 '24 15:06 sagudev

Or are you suggesting that we should actually replace all such patterns with actual error handling not just logging, so why bother with making it easier.

Yes, I think that at some point failed IPC messages will need to be handled via proper error handling and recovery since a failed IPC message can mean that the task the message is delivering to has disappeared. Maybe in the simplest case that means shutting the entire task down, but in some cases (the constellation for example) more will need to be done.

mrobinson avatar Jun 14 '24 15:06 mrobinson

Or are you suggesting that we should actually replace all such patterns with actual error handling not just logging, so why bother with making it easier.

Yes, I think that at some point failed IPC messages will need to be handled via proper error handling and recovery since a failed IPC message can mean that the task the message is delivering to has disappeared. Maybe in the simplest case that means shutting the entire task down, but in some cases (the constellation for example) more will need to be done.

should I do it part of this PR?

Taym95 avatar Jun 26 '24 11:06 Taym95

should I do it part of this PR?

If it's possible to write a macro to halt execution of the current function, trigger the shutdown of the WebGPU task cleaning up any resources, and then terminate the task -- that would be excellent, I think!

mrobinson avatar Jun 26 '24 13:06 mrobinson

should I do it part of this PR?

If it's possible to write a macro to halt execution of the current function, trigger the shutdown of the WebGPU task cleaning up any resources, and then terminate the task -- that would be excellent, I think!

What is task in this context? Because if it's just "WebGPU work that was send", that would leave page in unexpected state. Maybe we can just soft-crash the tab (just replacing current page with tab crashed page, so no actual crashing, so cleanup would be done by GC). Given that ipc fails very rarely, this would be nice enough solution.

sagudev avatar Jun 26 '24 13:06 sagudev

should I do it part of this PR?

If it's possible to write a macro to halt execution of the current function, trigger the shutdown of the WebGPU task cleaning up any resources, and then terminate the task -- that would be excellent, I think!

What is task in this context? Because if it's just "WebGPU work that was send", that would leave page in unexpected state. Maybe we can just soft-crash the tab (just replacing current page with tab crashed page, so no actual crashing, so cleanup would be done by GC). Given that ipc fails very rarely, this would be nice enough solution.

Does the WebGPU task keep any resources for ongoing Documents? If so, these will need to be cleaned up, even if the WebGPU task continues.

mrobinson avatar Jun 26 '24 13:06 mrobinson

should I do it part of this PR?

If it's possible to write a macro to halt execution of the current function, trigger the shutdown of the WebGPU task cleaning up any resources, and then terminate the task -- that would be excellent, I think!

What is task in this context? Because if it's just "WebGPU work that was send", that would leave page in unexpected state. Maybe we can just soft-crash the tab (just replacing current page with tab crashed page, so no actual crashing, so cleanup would be done by GC). Given that ipc fails very rarely, this would be nice enough solution.

Does the WebGPU task keep any resources for ongoing Documents? If so, these will need to be cleaned up, even if the WebGPU task continues.

They are cleaned when Drop of associated dom objects is called (dropping GPUBuffer will send DropBuffer to wgpu thread), although if the thread is dead (that's probably the reason for IPC failure), everything should already be cleaned up on wgpu side.

sagudev avatar Jun 26 '24 13:06 sagudev

They are cleaned when Drop of associated dom objects is called (dropping GPUBuffer will send DropBuffer to wgpu thread), although if the thread is dead (that's probably the reason for IPC failure), everything should already be cleaned up on wgpu side.

If the script process crashes, Drop implementations won't be called so what is the mechanism to ensure that resource are released on the WebGPU-side?

mrobinson avatar Jun 26 '24 16:06 mrobinson

They are cleaned when Drop of associated dom objects is called (dropping GPUBuffer will send DropBuffer to wgpu thread), although if the thread is dead (that's probably the reason for IPC failure), everything should already be cleaned up on wgpu side.

If the script process crashes, Drop implementations won't be called so what is the mechanism to ensure that resource are released on the WebGPU-side?

There isn't such mechanism (although wgpu internally does some cleanup beforehand, so the only thing that is kept alive is ID). Similar problem might also be present in WebGL.

I think we need to have more broad discussion how we will approach erroring and recovery in servo.

sagudev avatar Jun 26 '24 16:06 sagudev

I think we need to have more broad discussion how we will approach erroring and recovery in servo.

Yes, I agree. In general, Servo needs to be make much more resilient to process crashes, task panics, and IPC failures. I guess my only concern here is that we shouldn't be hiding away places where we are going to need to add real error handling in the future.

mrobinson avatar Jun 26 '24 16:06 mrobinson

I think we need to have more broad discussion how we will approach erroring and recovery in servo.

Yes, I agree. In general, Servo needs to be make much more resilient to process crashes, task panics, and IPC failures. I guess my only concern here is that we shouldn't be hiding away places where we are going to need to add real error handling in the future.

I think we need to have more broad discussion how we will approach erroring and recovery in servo.

Yes, I agree. In general, Servo needs to be make much more resilient to process crashes, task panics, and IPC failures. I guess my only concern here is that we shouldn't be hiding away places where we are going to need to add real error handling in the future.

I will close this PR, and I will check with @sagudev what we can do to add better error handling .

Taym95 avatar Jul 02 '24 14:07 Taym95