redwoodjs / redwood

The App Framework for Startups
https://redwoodjs.com
MIT License
17.35k stars 997 forks source link

[Bug?]: Server is killed and doesn't come back up when saving changes #11719

Open o0charlie0o opened 2 weeks ago

o0charlie0o commented 2 weeks ago

What's not working?

When the server restarts after making a code change it is killed and doesn't come back up. After some investigation it appears to have been introduced with this pr: https://github.com/redwoodjs/redwood/pull/11691

Essentially if the first promise wins then it resolves and await this.startApiServer() is called. The problem here is the second promise still executes so after 2 seconds it still kills the server anyways.

Running the following code in chrome dev tools console will demonstrate the issue:

const promise1 = new Promise((resolve) => {
  setTimeout(() => {
    console.log('Promise 1 resolved');
    resolve('First');
  }, 100);
});

const promise2 = new Promise((resolve) => {
  setTimeout(() => {
    console.log('Promise 2 resolved');
    resolve('Second');
  }, 200);
});

Promise.race([promise1, promise2]).then((value) => {
  console.log('Race settled with:', value);
});

Output is: Promise 1 resolved Race settled with: First Promise 2 resolved

How do we reproduce the bug?

Make a change in some code on the api side and save so the server restarts

What's your environment? (If it applies)

No response

Are you interested in working on this?

s98berg commented 1 week ago

After upgrading to 8.4.1 the same thing happens in my project that if I edit in the api the server shuts down and doesn't start again. I use vscode on mac. Really glad I found the bug report here, because I've spent hours debugging.

cadlagtrader commented 2 days ago

Same thing happening to me on 8.4.1 without editing any file.

It seems yarn rw dev api touch trustedDocumentSotore when starting and 8.4.1 fails to restart it

[change] /src/lib/trustedDocumentsStore.ts