Skip to content

Synchronize agentCoreIsStable() (i.e. await finalization db and actions) #6813

@redneck-f25

Description

@redneck-f25

Is your feature request related to a problem? Please describe.
If the MeshAgent core becomes stable, some work is done in meshagent.js::agentCoreIsStable() and finally the plugins are notified by hook_agentCoreIsStable().

Most of the work is async (mongo) and distributed over the network (actions) and not finished when hook_agentCoreIsStable() is called. Especially the "sysinfo" action takes a long time on Windows whereby meshcore.js::getSystemInformation() blocks the Duktape engine.

Describe the solution you'd like
Let MeshCentral und MeshAgent calm down before notifying the plugins. The jobs could be synchronized with Promises.

See PR.

Describe alternatives you've considered
That's not really an option: await new Promise((resolve) => setTimeout(resolve, 30000)); ;-)

Additional context
With some more debug code (fix/synchronize-agent-core-is-stable-debug) I got some timings from different machines and with different config. In the first column milliseconds since the call of CreateMeshAgent().

EDIT: In either case hook_agentCoreIsStable() is called (long) be before RESOLVE Promise sysinfo.

       0 CREATE MeshArgent
    2713 CREATE Promise FetchDiagnosticAgentNodeId
    2714 CREATE Promise FetchSystemInformation
    2715 CREATE Promise AgentErrorLogDump
    2716 CREATE Promise IP location
    2719 RESOLVE Promise FetchDiagnosticAgentNodeId
    2719 CREATE Promise sysinfo
    2719 RESOLVE Promise FetchSystemInformation
    2720 CREATE Promise errorlog
    2720 RESOLVE Promise AgentErrorLogDump
    2734 RESOLVE Promise IP location
    2735 ALL PROMISES RESOLVED
    8573 RESOLVE Promise sysinfo
    8577 RESOLVE Promise errorlog
    8577 ALL PROMISES RESOLVED
    8579 AGENT CORE IS STABLE
       0 CREATE MeshArgent
    3012 CREATE Promise FetchDiagnosticAgentNodeId
    3013 CREATE Promise FetchSystemInformation
    3014 CREATE Promise AgentErrorLogDump
    3014 CREATE Promise IP location
    3017 RESOLVE Promise FetchDiagnosticAgentNodeId
    3017 CREATE Promise errorlog
    3017 RESOLVE Promise AgentErrorLogDump
    3018 CREATE Promise sysinfo
    3018 RESOLVE Promise FetchSystemInformation
    3020 RESOLVE Promise IP location
    3020 ALL PROMISES RESOLVED
    6398 RESOLVE Promise errorlog
   19061 RESOLVE Promise sysinfo
   19061 ALL PROMISES RESOLVED
   19063 AGENT CORE IS STABLE
       0 CREATE MeshArgent
     114 CREATE Promise FetchDiagnosticAgentNodeId
     115 CREATE Promise FetchSystemInformation
     116 CREATE Promise AgentErrorLogDump
     116 CREATE Promise IP location
     118 RESOLVE Promise FetchDiagnosticAgentNodeId
     119 CREATE Promise sysinfo
     119 RESOLVE Promise FetchSystemInformation
     119 CREATE Promise errorlog
     119 RESOLVE Promise AgentErrorLogDump
     122 RESOLVE Promise IP location
     122 ALL PROMISES RESOLVED
     328 RESOLVE Promise sysinfo
     330 RESOLVE Promise errorlog
     330 ALL PROMISES RESOLVED
     331 AGENT CORE IS STABLE
       0 CREATE MeshArgent
     101 CREATE Promise FetchDiagnosticAgentNodeId
     102 CREATE Promise FetchSystemInformation
     105 RESOLVE Promise FetchDiagnosticAgentNodeId
     106 CREATE Promise sysinfo
     106 RESOLVE Promise FetchSystemInformation
     106 ALL PROMISES RESOLVED
     161 RESOLVE Promise sysinfo
     161 ALL PROMISES RESOLVED
     163 AGENT CORE IS STABLE

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions