Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WasmFS] Add a hack to work around deadlocks #17869

Merged
merged 3 commits into from
Nov 1, 2022
Merged

Conversation

tlively
Copy link
Member

@tlively tlively commented Sep 16, 2022

When the main thread tries to perform a WasmFS operation that tries to acquire a
lock that is already held by another thread that is trying to proxy a backend
operation, deadlock can occur. Proxying depends on passing a message to a worker
thread and that message has to be relayed through the main thread. When the main
thread is spinning on a lock, the proxying message is not relayed and neither
thread makes forward progress.

Work around the issue by adding a heartbeat event on the dedicated worker thread
to make it execute the queue periodically even without receiving a message from
the main thread. This allows the proxying thread holding the lock to make
forward progress and resolves the deadlock.

@tlively
Copy link
Member Author

tlively commented Sep 16, 2022

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

Comment on lines 39 to 43
var heartbeat = () => {
_emscripten_proxy_execute_queue($0);
setTimeout(heartbeat, 50);
};
heartbeat();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var heartbeat = () => {
_emscripten_proxy_execute_queue($0);
setTimeout(heartbeat, 50);
};
heartbeat();
var intervalID = setInterval(() => {
if (ABORT) {
clearInterval(intervalID);
} else {
_emscripten_proxy_execute_queue($0);
}
}, 1000);

system/lib/wasmfs/thread_utils.h Outdated Show resolved Hide resolved
When the main thread tries to perform a WasmFS operation that tries to acquire a
lock that is already held by another thread that is trying to proxy a backend
operation, deadlock can occur. Proxying depends on passing a message to a worker
thread and that message has to be relayed through the main thread. When the main
thread is spinning on a lock, the proxying message is not relayed and neither
thread makes forward progress.

Work around the issue by adding a heartbeat event on the dedicated worker thread
to make it execute the queue periodically even without receiving a message from
the main thread. This allows the proxying thread holding the lock to make
forward progress and resolves the deadlock.
@tlively tlively marked this pull request as ready for review October 31, 2022 22:14
@tlively tlively requested a review from kripken October 31, 2022 22:14
Comment on lines 49 to 51
}, queue.queue);

// Sit in the event loop performing work as it comes in.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indentation looks wrong. Should the entire EM_ASM be indented two more?

@tlively tlively merged commit 54ea5cf into main Nov 1, 2022
@tlively tlively deleted the wasmfs-hacky-deadlock-fix branch November 1, 2022 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants