-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Release runtime keepalive in emscripten_clear_timeout and make clear_timeout/clear_immediate idempotent #27720
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
Merged
guybedford
merged 6 commits into
emscripten-core:main
from
guybedford:timeout-keepalive
Sep 17, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
46a4bda
Release runtime keepalive in emscripten_clear_timeout and make clear_…
guybedford 82f0cad
rebaseline
guybedford 3f31356
Use safeSetTimeout.mapping for timeout handles, add safeClearTimeout
guybedford 7bf18d9
SDL_RemoveTimer: use safeClearTimeout for safeSetTimeout ids
guybedford d7506cd
rebaseline
guybedford a8ce995
Add PR number to changelog, drop wall-clock check from clear_timeout …
guybedford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| { | ||
| "hello_world.js": 54683, | ||
| "hello_world.js.gz": 17343, | ||
| "hello_world.js": 54705, | ||
| "hello_world.js.gz": 17355, | ||
| "hello_world.wasm": 14279, | ||
| "hello_world.wasm.gz": 7101, | ||
| "no_asserts.js": 23596, | ||
| "no_asserts.js.gz": 8277, | ||
| "no_asserts.wasm": 11393, | ||
| "no_asserts.wasm.gz": 5646, | ||
| "strict.js": 51834, | ||
| "strict.js.gz": 16342, | ||
| "strict.js": 51856, | ||
| "strict.js.gz": 16348, | ||
| "strict.wasm": 14279, | ||
| "strict.wasm.gz": 7098, | ||
| "total": 170064, | ||
| "total_gz": 61807 | ||
| "total": 170108, | ||
| "total_gz": 61825 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #include <assert.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <emscripten/eventloop.h> | ||
|
|
||
| int fired_id; | ||
|
|
||
| void never(void *arg) { | ||
| printf("cleared callback ran\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| void fired(void *arg) { | ||
| printf("fired\n"); | ||
| // Clearing an id that already fired must be a no-op. | ||
| emscripten_clear_timeout(fired_id); | ||
| emscripten_clear_timeout(fired_id); | ||
| } | ||
|
|
||
| void immediate_fired(void *arg) { | ||
| emscripten_clear_immediate(fired_id); | ||
| emscripten_clear_immediate(fired_id); | ||
| } | ||
|
|
||
| // Only runs if the runtime actually exits. | ||
| void at_exit() { | ||
| printf("done\n"); | ||
| } | ||
|
|
||
| int main() { | ||
| atexit(at_exit); | ||
| #if MODE_CLEARED | ||
| // Clearing a pending timeout releases its keepalive so the runtime exits | ||
| // from main without waiting for it (a leak fails the check below; a timer | ||
| // that was not actually cleared aborts when it fires). | ||
| int id = emscripten_set_timeout(never, 1000, NULL); | ||
| assert(emscripten_runtime_keepalive_check()); | ||
| emscripten_clear_timeout(id); | ||
| assert(!emscripten_runtime_keepalive_check()); | ||
| return 42; | ||
| #elif MODE_IDEMPOTENT | ||
| int id = emscripten_set_timeout(never, 1000, NULL); | ||
| emscripten_clear_timeout(id); | ||
| emscripten_clear_timeout(id); | ||
| fired_id = emscripten_set_timeout(fired, 0, NULL); | ||
| // Still-pending timer must keep the runtime alive until it fires. | ||
| emscripten_set_timeout(fired, 50, NULL); | ||
| return 0; | ||
| #elif MODE_IMMEDIATE | ||
| int id = emscripten_set_immediate(never, NULL); | ||
| emscripten_clear_immediate(id); | ||
| emscripten_clear_immediate(id); | ||
| fired_id = emscripten_set_immediate(immediate_fired, NULL); | ||
| emscripten_set_timeout(fired, 50, NULL); | ||
| return 0; | ||
| #else | ||
| emscripten_set_timeout(fired, 50, NULL); | ||
| return 0; | ||
| #endif | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.