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

List routes command fails #4

Closed
targos opened this issue Apr 30, 2022 · 18 comments
Closed

List routes command fails #4

targos opened this issue Apr 30, 2022 · 18 comments
Assignees
Labels
bug Something isn't working

Comments

@targos
Copy link

targos commented Apr 30, 2022

Happy to provide more information if you need it. node ace list:routes (with or without --json) works fine in the terminal.

image

@Julien-R44
Copy link
Owner

It's weird, I can't really say why.
Is it possible for you to share the return of node ace list:routes --json?

I can't reproduce the problem, either on Mac/Linux/Windows and I tried on several projects with different routes
( Thank you for taking the time to write all these issues 👍 )

@Julien-R44 Julien-R44 added the bug Something isn't working label Apr 30, 2022
@Julien-R44 Julien-R44 self-assigned this Apr 30, 2022
@targos
Copy link
Author

targos commented Apr 30, 2022

I can't really share it (it's private customer's code)

@targos
Copy link
Author

targos commented Apr 30, 2022

Would there be a way for me to debug it locally? I'd like to add a breakpoint where the JSON.parse happens.

@Julien-R44
Copy link
Owner

The only way I can see right now would be to clone the repo and debug locally 😓

That said, it's very simple, basically: clone, npm install, add a breakpoint here:

const jsonRoutes = JSON.parse(rawRoutes)

Then press F5, it opens a new VSCode editor, open the problematic project in it, and do the ListRoutes thing

Sorry to ask you this, I guess it's just a small error 😓
However, no hurry if you don't have much time right now, I'll investigate a bit more on my side.

@targos
Copy link
Author

targos commented May 1, 2022

What I found is that the result of the command is truncated (the end of the output is missing).
I'm not sure it will work (and I don't have more time now to try, maybe this evening), but I suggest that instead of doing cd xxx && command, you run the command using the cwd option

command = `node ace ${command}`
let cmd =
platform === 'win32' && !Config.misc.useUnixCd
? `cd /d "${adonisProject.path}" && ${command}`
: `cd "${adonisProject.path}" && ${command}`

https://nodejs.org/dist/latest-v18.x/docs/api/child_process.html#child_processexeccommand-options-callback

@targos
Copy link
Author

targos commented May 1, 2022

I tried it (and I think it's better that way regardless), but that doesn't fix the problem.

@targos
Copy link
Author

targos commented May 1, 2022

This is probably nodejs/node#19218

@targos
Copy link
Author

targos commented May 1, 2022

If I understand the problem correctly, the bug is actually in ace/AdonisJS, where process.exit is called while there is still something in the queue to be printed to stdout.

@targos
Copy link
Author

targos commented May 1, 2022

@thetutlage is that possible?

@thetutlage
Copy link
Collaborator

@targos Maybe. Since you are debugging it all locally. Can you please add stayAlive property to this command https://github.com/adonisjs/core/blob/develop/commands/ListRoutes/index.ts#L62

@Julien-R44
Copy link
Owner

Thank you for investigating Michaël

On my side, impossible to reproduce the problem, even with more than +500 different defined routes and thus a consequent output 🤔

@targos
Copy link
Author

targos commented May 1, 2022

Are you on a Mac @Julien-R44 ?

@Julien-R44
Copy link
Owner

Mostly on Windows, but I have a mac and ubuntu on hand and have been unable to reproduce the bug on all three different configurations. You are experiencing this bug on Windows, right?

@targos
Copy link
Author

targos commented May 1, 2022

No, I can only reproduce on Mac. No issues with the same project on Windows.

@Julien-R44
Copy link
Owner

Julien-R44 commented May 1, 2022

Ok finally the problem occurs under my mac with my file containing more than 500 routes !

@thetutlage I was able to add stayAlive to true on ListRoutes, and indeed the problem disappears.
I also tried to increase the maxBuffer property all the way, but the problem persists.

Should we add this stayAlive on ListRoutes? I don't know if this is the right solution, I will read more about it

@thetutlage
Copy link
Collaborator

thetutlage commented May 1, 2022

stayLive is okay to use, since it waits for the Node process to shutdown gracefully. Just make sure to call await this.application.shutdown() inside the command run method.

@Julien-R44
Copy link
Owner

Future readers, if you encounter the same issue :
Upgrade adonisjs/core to at least 5.7.6 and run node ace generate:manifest

@thetutlage
Copy link
Collaborator

Is it true that this is indeed an issue nodejs/node#19218, which is caused by exiting the process with process.exit call?

And the only available solution right now is to let the process shutdown gracefully?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants