Skip to content

Commit 1a5a6c3

Browse files
gahaasCommit Bot
authored andcommitted
[wasm] Notify StreamingDecoder when its AsyncCompileJob is destructed
The lifetime of the AsyncCompileJob does not depend on the lifetime of the stream which feeds data into it. Multiple checks guarantee that the AsyncCompileJob still exists when the stream wants to call it. With this CL we add an additional level of defense to make sure that streaming does not continue after the AsyncCompileJob got destructed. It is not clear if this CL fixes the bug referenced below. However, the crashes there could be caused when streaming accesses the AsyncCompileJob after it got destructed already. I was not able though to find a scenario where this is possible. [email protected] Bug: chromium:888170 Change-Id: Id5c6cc34842735a3adaf3e09c57cbe923cfc2630 Reviewed-on: https://chromium-review.googlesource.com/1241961 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Clemens Hammacher <[email protected]> Cr-Commit-Position: refs/heads/master@{#56213}
1 parent 3a00ba5 commit 1a5a6c3

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/wasm/module-compiler.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,11 @@ std::shared_ptr<StreamingDecoder> AsyncCompileJob::CreateStreamingDecoder() {
22542254
AsyncCompileJob::~AsyncCompileJob() {
22552255
background_task_manager_.CancelAndWait();
22562256
if (native_module_) native_module_->compilation_state()->Abort();
2257+
// Tell the streaming decoder that the AsyncCompileJob is not available
2258+
// anymore.
2259+
// TODO(ahaas): Is this notification really necessary? Check
2260+
// https://crbug.com/888170.
2261+
if (stream_) stream_->NotifyCompilationEnded();
22572262
CancelPendingForegroundTask();
22582263
for (auto d : deferred_handles_) delete d;
22592264
}
@@ -2285,7 +2290,6 @@ void AsyncCompileJob::FinishCompile() {
22852290
}
22862291

22872292
void AsyncCompileJob::AsyncCompileFailed(Handle<Object> error_reason) {
2288-
if (stream_) stream_->NotifyError();
22892293
// {job} keeps the {this} pointer alive.
22902294
std::shared_ptr<AsyncCompileJob> job =
22912295
isolate_->wasm_engine()->RemoveCompileJob(this);

src/wasm/streaming-decoder.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ class V8_EXPORT_PRIVATE StreamingDecoder {
6565

6666
void Abort();
6767

68-
// Notify the StreamingDecoder that there has been an compilation error.
69-
void NotifyError() { ok_ = false; }
68+
// Notify the StreamingDecoder that compilation ended and the
69+
// StreamingProcessor should not be called anymore.
70+
void NotifyCompilationEnded() {
71+
// We set {ok_} to false to turn all future calls to the StreamingDecoder
72+
// into no-ops.
73+
ok_ = false;
74+
}
7075

7176
private:
7277
// TODO(ahaas): Put the whole private state of the StreamingDecoder into the

0 commit comments

Comments
 (0)