ForestAdmin / agent-nodejs

🌱 Node.js agent for Forest Admin
GNU General Public License v3.0
67 stars 8 forks source link

Route bootstrap hangs indefinitely #608

Closed tobiasdiez closed 1 year ago

tobiasdiez commented 1 year ago

Expected behavior

Starting the agent with agent.start() works.

Actual behavior

However, it hangs forever.

Failure Logs

There are no relevant logs printed. I tried to debug it and found out that execution of these promises never finishes: https://github.com/ForestAdmin/agent-nodejs/blob/dd3a18cb9c168381c52e7c70c511e3b9391758f4/packages/agent/src/agent.ts#L150. I'm not exactly sure which route is the issue, but I think it is the authentication route.

In fact, looking at https://github.com/ForestAdmin/agent-nodejs/blob/dd3a18cb9c168381c52e7c70c511e3b9391758f4/packages/forestadmin-client/src/utils/server.ts#L18-L24, there are no timeouts specified and thus I think it waits forever for a response: https://ladjs.github.io/superagent/#timeouts

But this doesn't really explain why there is no response from the auth server in the first place...

Context

The code I'm using can be found at https://github.com/JabRef/JabRefOnline/pull/1345. Just follow https://github.com/JabRef/JabRefOnline#getting-started to setup the local db, and then run yarn dev which starts the server. After that the forestadmin backend should be available at http://localhost:3000/_admin, but actually the server does not respond.

I've also tried to play around with the standalone mount: yarn node .\server\adminsimple.js. But this fails with

D:\Programming\JabRefOnline\node_modules\sequelize\lib\sequelize.js:135
      throw new Error("Dialect needs to be explicitly supplied as of v4.0.0");
            ^

Error: Dialect needs to be explicitly supplied as of v4.0.0
    at new Sequelize (D:\Programming\JabRefOnline\node_modules\sequelize\lib\sequelize.js:135:13)  
    at createEmptySequelize (D:\Programming\JabRefOnline\node_modules\@forestadmin\datasource-sql\dist\index.js:19:11)
    at buildSequelizeInstance (D:\Programming\JabRefOnline\node_modules\@forestadmin\datasource-sql\dist\index.js:29:23)
    at D:\Programming\JabRefOnline\node_modules\@forestadmin\datasource-sql\dist\index.js:38:33    
    at D:\Programming\JabRefOnline\node_modules\@forestadmin\datasource-customizer\dist\datasource-customizer.js:46:36
    at DecoratorsStack.applyQueuedCustomizations (D:\Programming\JabRefOnline\node_modules\@forestadmin\datasource-customizer\dist\decorators\decorators-stack.js:73:47)
    at DataSourceCustomizer.getDataSource (D:\Programming\JabRefOnline\node_modules\@forestadmin\datasource-customizer\dist\datasource-customizer.js:114:26)
    at Agent.start (D:\Programming\JabRefOnline\node_modules\@forestadmin\agent\dist\agent.js:56:50)
    at file:///D:/Programming/JabRefOnline/server/adminsimple.js:17:37
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
jeffladiray commented 1 year ago

Hey @tobiasdiez :wave:

For the second part of your issue (throw new Error("Dialect needs to be explicitly supplied as of v4.0.0");), the error is raised by Sequelize. Running only yarn node .\server\adminsimple.js will not read the content of .env file by default. So, for the mountOnStandalone version of your code, you should be able to make it run via the usage of the dotenv package. Let me know if that's the case 🙏

For the first part of the issue (About the authentication), I've forwarded this to the team in charge of this topic, that should answer you shortly 👍

realSpok commented 1 year ago

Hi,

I have been looking through the server logs and couldn't find any error or timeout on the authentication routes (max is a couple seconds). Could you please retry and see if the issue persists. If so, could you please provide a timestamp of the attempt so that we can see if the error shows up in the server logs.

Thanks

tobiasdiez commented 1 year ago

Thanks @jeffladiray and @realSpok for your help!

First of all, of course, loading the env file fixed the mountOnStandalone issue. So that's resolved. I think, I've also found a solution to my original problem. It was a combination of async promises and connection errors being hidden by nuxt. So sorry for the noise.

I think however that there should be a timeout on the superagent request. What do you think?

jeffladiray commented 1 year ago

I guess we missed this answer :'(

i've created a ticket to add a timeout on those superagent calls as it would have been easier to understand the issue indeed.

I'm closing this, as the global issue is resolved on your end, and we'll let you know once the timeout is added on those calls.

Thanks for your feedback 🙏