From: Richard Musiol Date: Tue, 12 Mar 2019 22:40:03 +0000 (+0100) Subject: misc/wasm: add workaround for missed timeout events X-Git-Tag: go1.13beta1~1035 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=47e42cdadc4abeb28ff21930bfe22210dcb9abd4;p=gostls13.git misc/wasm: add workaround for missed timeout events TryBot is sometimes running into deadlocks on js/wasm. We haven't been able to reproduce them yet. This workaround is an experiment to resolve these deadlocks by retrying a missed timeout event. A timeout event is scheduled by Go to be woken by JavaScript after a certain amount of time. The checkTimeouts function then checks which notes to wake by comparing their deadline to nanotime. If this check fails erroneously then the note may stay asleep forever, causing a deadlock. This may or may not be the reason of the observed deadlocks. Updates #28975. Change-Id: I46b9d4069307142914f0e7b3acd4e65578319f0b Reviewed-on: https://go-review.googlesource.com/c/go/+/167119 Reviewed-by: Brad Fitzpatrick --- diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js index 8eff751d62..e939e8527a 100644 --- a/misc/wasm/wasm_exec.js +++ b/misc/wasm/wasm_exec.js @@ -265,7 +265,15 @@ const id = this._nextCallbackTimeoutID; this._nextCallbackTimeoutID++; this._scheduledTimeouts.set(id, setTimeout( - () => { this._resume(); }, + () => { + this._resume(); + while (this._scheduledTimeouts.has(id)) { + // for some reason Go failed to register the timeout event, log and try again + // (temporary workaround for https://github.com/golang/go/issues/28975) + console.warn("scheduleTimeoutEvent: missed timeout event"); + this._resume(); + } + }, getInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early )); mem().setInt32(sp + 16, id, true);