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

worker: fix interaction of terminate() with messaging port #37319

Closed

Commits on Feb 11, 2021

  1. worker: fix interaction of terminate() with messaging port

    When a Worker is terminated, its own handle and the public
    `MessagePort` are `.ref()`’ed, so that all relevant events,
    including the `'exit'` events, end up being received.
    
    However, this is problematic if messages end up being queued
    from the Worker between the beginning of the `.terminate()` call
    and its completion, and there are no `'message'` event handlers
    present at that time. In that situation, currently the messages
    would not end up being processed, and since the MessagePort
    is still `.ref()`’ed, it would keep the event loop alive
    indefinitely.
    
    To fix this:
    
    - Make sure that all messages end up being received by
      `drainMessagePort()`, including cases in which the port had
      been stopped (i.e. there are no `'message'` listeners) and
      cases in which we exceed the limit for messages being processed
      in one batch.
    - Unref the Worker’s internal ports manually after the Worker
      has exited.
    
    Either of these solutions should be solving this on its own,
    but I think it makes sense to make sure that both of them
    happen during cleanup.
    addaleax committed Feb 11, 2021
    Configuration menu
    Copy the full SHA
    2eab6c7 View commit details
    Browse the repository at this point in the history