Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
fix(plugins): stop the install preflight from evicting a live plugin's identity
Gabe Kangasf067ef734140
diff --git a/services/plugins/manager.go b/services/plugins/manager.goindex b1631afb62..996c536ce5 100644--- a/services/plugins/manager.go+++ b/services/plugins/manager.go@@ -683,11 +683,31 @@ func validateUploadedPackage(ctx context.Context, env *HostEnv, packageBytes []bassetsFS = sub}}+ // The plugin registry is process-global and keyed by slug: loadFromBytes+ // put()s the slug and the trailing Close() remove()s it. If a plugin of this+ // slug is already loaded and enabled, this throwaway preflight would delete+ // the live instance's identity, after which every gated host call from the+ // still-running plugin resolves as "not found" and silently no-ops until a+ // reload. Snapshot the existing entry and restore it after the preflight.+ //+ // ponytail: this still points the slug at the preflight identity *during*+ // the load itself, which is harmless in practice (same slug and KV+ // namespace; the new manifest's permission set differs only for the tens of+ // ms of a manual install). If that window ever matters, load the preflight+ // under an isolated registry key instead of the real slug.+ prevID, hadPrev := globalPluginRegistry.get(manifest.Slug)+ restoreLiveIdentity := func() {+ if hadPrev {+ globalPluginRegistry.put(prevID)+ }+ }loaded, err := loadFromBytes(ctx, env, manifestBytes, codeBytes, runtimeType, manifest.Slug, assetsFS)if err != nil {+ restoreLiveIdentity()return nil, err}loaded.Close(ctx)+ restoreLiveIdentity()return manifest, nil}diff --git a/services/plugins/package_test.go b/services/plugins/package_test.goindex c2bcf1ee03..cb039fc5be 100644--- a/services/plugins/package_test.go+++ b/services/plugins/package_test.go@@ -70,6 +70,47 @@ func validManifestBytes() []byte {}`)}+// TestValidateUploadedPackage_PreservesLiveIdentity is the C2 regression: the+// install preflight loads the uploaded package through the real load path,+// which put/removes the slug in the process-global identity registry. It must+// NOT evict a still-running plugin of the same slug (an update), which would+// leave the live instance unable to resolve its own host calls until a reload.+func TestValidateUploadedPackage_PreservesLiveIdentity(t *testing.T) {+ ctx := context.Background()+ compiledEngines.resetForTest(ctx)+ t.Cleanup(func() { compiledEngines.resetForTest(ctx) })++ const slug = "c2-live"+ env, _, _ := captureEnv()++ // Stand in for a live, enabled instance registered for host-call routing.+ liveID := &pluginIdentity{slug: slug, granted: map[string]bool{PermChatSend: true}}+ globalPluginRegistry.put(liveID)+ t.Cleanup(func() { globalPluginRegistry.remove(slug) })++ // Preflight an "update" .ocpkg for the SAME slug.+ pkgPath := buildPkg(t, map[string][]byte{+ "plugin.manifest.json": []byte(`{"api":"1","name":"C2 Live","slug":"c2-live","version":"0.2.0"}`),+ "plugin.js": []byte(`const { definePlugin } = require("@owncast/plugin-sdk"); module.exports = definePlugin({});`),+ })+ pkgBytes, err := os.ReadFile(pkgPath)+ if err != nil {+ t.Fatalf("read pkg: %v", err)+ }++ if _, err := validateUploadedPackage(ctx, env, pkgBytes); err != nil {+ t.Fatalf("validateUploadedPackage: %v", err)+ }++ got, ok := globalPluginRegistry.get(slug)+ if !ok {+ t.Fatal("preflight removed the live plugin's identity from the registry")+ }+ if got != liveID {+ t.Fatal("preflight left a stale (preflight) identity instead of the live one")+ }+}+func TestLoadPackage_MissingManifest(t *testing.T) {path := buildPkg(t, map[string][]byte{pkgWasmFilename: {0x00}, // not parsed; the manifest check fails first