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

Busy-loop code makes it impossible to attach inspector #16725

Open
bartlomieju opened this issue Nov 20, 2022 · 2 comments
Open

Busy-loop code makes it impossible to attach inspector #16725

bartlomieju opened this issue Nov 20, 2022 · 2 comments
Assignees
Labels
inspector related to the inspector integration

Comments

@bartlomieju
Copy link
Member

Following situation works with --inspect-brk but not with --inspect.

Screen recording:

Screen.Recording.2022-11-20.at.20.08.02.mov

Notice that I can't open any file, start a memory profile or CPU profile.

@bartlomieju bartlomieju added the inspector related to the inspector integration label Nov 20, 2022
@bartlomieju bartlomieju self-assigned this Nov 20, 2022
@bartlomieju
Copy link
Member Author

Current working thesis: contextCreated notification doesn't always arrive to CDP (checked packets with WireShark). It seems there's a race condition when this notification is sent. Needs more investigation.

@bartlomieju
Copy link
Member Author

Investigated more, this specific problem happens with this code:

let i = 0;

while (true) {
  doSomething(10000);
  i++;
}

function doSomething(breakDuration) {
  console.log("hello %i", i);
  console.timeStamp();

  const started = performance.now();
  let canBreak = false;

  while (!canBreak) {
    canBreak = performance.now() - started >= breakDuration;
  }
}

It's a synchronous code that runs busy loop. The problem stems from the fact that control is never yielded back to the event loop and thus it has no chance to pump messages from the inspector which in turn causes it to never properly attach.

@bartlomieju bartlomieju changed the title Sometimes can't debug with --inspect flag, only --inspect-brk Busy-loop code makes it impossible to attach inspector Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inspector related to the inspector integration
Projects
None yet
Development

No branches or pull requests

1 participant