Skip to content

fix: correct event loop starvation and memory leak in JS handler#32

Merged
jeeyo merged 5 commits into
claude/integrate-httparse-4CWjjfrom
fix-event-loop-handler-16361771415626745393
Jun 18, 2026
Merged

fix: correct event loop starvation and memory leak in JS handler#32
jeeyo merged 5 commits into
claude/integrate-httparse-4CWjjfrom
fix-event-loop-handler-16361771415626745393

Conversation

@jeeyo

@jeeyo jeeyo commented Mar 27, 2026

Copy link
Copy Markdown
Owner

The integration tests were previously failing due to multiple issues with the eval_import_wrapper execution and the JsContext::poll event loop.

  • The HTTP handler would spin up to 1000 iterations without yielding to the OS if there was an active timeout (like the one present in handler.js), breaking async/await flows.
  • Modified src/js/context.rs to return a PollStatus enum from poll() that enables the HTTP handler to know if it should continue (jobs were executed), isere_k_msleep (timers are waiting), or break (idle).
  • Memory leak in handler_callback fixed by replacing the loop calling qjs::JS_FreeAtom on each property with a final call to qjs::JS_FreePropertyEnum on the array to properly free the memory.
  • QuickJS evaluation and execution functions now pull and log exceptions to printk via qjs::JS_GetException which greatly aids debugging.

PR created automatically by Jules for task 16361771415626745393 started by @jeeyo

- Replace `JS_FreeAtom` loop with `JS_FreePropertyEnum` to fix memory leak when getting property names
- Introduce `PollStatus` enum for `JsContext::poll` to properly differentiate between idle, executing jobs, and waiting for active timers
- Use `isere_k_msleep` (wrapped Zephyr `k_msleep`) to yield the thread when timers are active instead of spinning aggressively and exhausting iterations, which prevents the OS from firing the timers
- Print `JS_GetException` outputs during execution and evaluation functions to capture QuickJS exceptions and errors correctly
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

jeeyo and others added 4 commits March 27, 2026 18:32
- Add missing `pull_request` triggers in `.github/workflows/ci.yml` so tests run on all PRs
- Replace `JS_FreeAtom` loop with `JS_FreePropertyEnum` to fix memory leak when getting property names
- Introduce `PollStatus` enum for `JsContext::poll` to properly differentiate between idle, executing jobs, and waiting for active timers
- Use `isere_k_msleep` (wrapped Zephyr `k_msleep`) to yield the thread when timers are active instead of spinning aggressively and exhausting iterations, which prevents the OS from firing the timers
- Print `JS_GetException` outputs during execution and evaluation functions to capture QuickJS exceptions and errors correctly
… into fix-event-loop-handler-16361771415626745393
@jeeyo
jeeyo merged commit 69cf27f into claude/integrate-httparse-4CWjj Jun 18, 2026
3 checks passed
@jeeyo
jeeyo deleted the fix-event-loop-handler-16361771415626745393 branch June 18, 2026 03:08
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.

1 participant