Restore failure handling

We probably leak some threads and resources, e.g. when the script task crashes and doesn't get a chance to send layout data back to layout to be deallocated.

Not tested with iframes yet.