Skip to content

backend: plugins: Race condition with plugins on some systems #1772

@illume

Description

@illume

There's a race condition for when files are copied into place when doing an npm start from within a plugin, and the backend being able to see if a file exists inside GeneratePluginPaths.

This is the error in the backend:

{
  "level":"info",
  "pluginPath":"/home/user/.config/Headlamp/plugins/change-logo/main.js",
  "source":"/home/runner/work/headlamp/headlamp/backend/pkg/plugins/plugins.go","line":131,
  "error":"stat /home/user/.config/Headlamp/plugins/change-logo/main.js: no such file or directory",
  "time":"2024-03-06T17:42:59+05:30",
  "message":"Not including plugin path, main.js not found"
}

But when doing an ls on the file it is there.
When npm start inside the plugin is stopped, the issue disapears.

So there seems to be a race condition.

To reproduce

# Have backend running in one terminal.
make run-backend

# In the other terminal

cd examples/plugins/change-logo/
npm i
npm start

Notes

  • plugins.go@HandlePluginEvents is the code which watches for events and runs the path generation
  • headlamp-plugin.js@copyToPluginsFolder is what copies the plugin files using some webpack code "FileManagerPlugin". Not sure if it does atomic moves, or if removes and deletes inside.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendIssues related to the backendkind/bugCategorizes issue or PR as related to a bug.pluginspriority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.

    Type

    No type

    Projects

    Status

    Queued

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions