mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(test_ffi): thread_safe_callback is flaky (#19640)
Attempts to fix the thread_safe_callback flakiness. It's unclear what the flake is about, the exit code is apparently `C0000005` or `ACCESS_VIOLATION`, pointing to an issue with memory access. My only guess is that maybe dropping the `Option<extern "C" fn ()>` is somehow checking the validity of the function pointer and since the function has been dropped, the pointer is no longer valid and sometimes points to memory that should not be accessed. So now the will explicitly drop the functions before they get deallocated. If this doesn't fix the flake then something beyond my understanding is wrong.
This commit is contained in:
parent
30f2cd3d1e
commit
3be5381060
3 changed files with 8 additions and 1 deletions
|
@ -176,8 +176,10 @@ fn thread_safe_callback() {
|
||||||
let expected = "\
|
let expected = "\
|
||||||
Callback on main thread\n\
|
Callback on main thread\n\
|
||||||
Callback on worker thread\n\
|
Callback on worker thread\n\
|
||||||
|
STORED_FUNCTION cleared\n\
|
||||||
Calling callback, isolate should stay asleep until callback is called\n\
|
Calling callback, isolate should stay asleep until callback is called\n\
|
||||||
Callback being called\n\
|
Callback being called\n\
|
||||||
|
STORED_FUNCTION cleared\n\
|
||||||
Isolate should now exit\n";
|
Isolate should now exit\n";
|
||||||
assert_eq!(stdout, expected);
|
assert_eq!(stdout, expected);
|
||||||
assert_eq!(stderr, "");
|
assert_eq!(stderr, "");
|
||||||
|
|
|
@ -71,6 +71,8 @@ dylib.symbols.call_stored_function();
|
||||||
|
|
||||||
// Unref both main and worker thread callbacks and terminate the worker: Note, the stored function pointer in lib is now dangling.
|
// Unref both main and worker thread callbacks and terminate the worker: Note, the stored function pointer in lib is now dangling.
|
||||||
|
|
||||||
|
dylib.symbols.store_function(null);
|
||||||
|
|
||||||
mainThreadCallback.unref();
|
mainThreadCallback.unref();
|
||||||
await sendWorkerMessage("unref");
|
await sendWorkerMessage("unref");
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
|
@ -90,6 +92,9 @@ cleanupCallback.ref();
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
cleanupCallback.unref();
|
cleanupCallback.unref();
|
||||||
|
dylib.symbols.store_function(null);
|
||||||
|
mainThreadCallback.close();
|
||||||
|
cleanupCallback.close();
|
||||||
console.log("Isolate should now exit");
|
console.log("Isolate should now exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ self.addEventListener("message", ({ data }) => {
|
||||||
} else if (data === "call") {
|
} else if (data === "call") {
|
||||||
dylib.symbols.call_stored_function();
|
dylib.symbols.call_stored_function();
|
||||||
} else if (data === "unref") {
|
} else if (data === "unref") {
|
||||||
callback.unref();
|
callback.close();
|
||||||
}
|
}
|
||||||
self.postMessage("done");
|
self.postMessage("done");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue