MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / UnloadPlugin

Method UnloadPlugin

internal/pluginhost/host.go:379–429  ·  view source on GitHub ↗

UnloadPlugin removes one plugin from the active runtime and closes its dynamic library.

(id string)

Source from the content-addressed store, hash-verified

377
378// UnloadPlugin removes one plugin from the active runtime and closes its dynamic library.
379func (h *Host) UnloadPlugin(id string) bool {
380 if h == nil {
381 return false
382 }
383 id = strings.TrimSpace(id)
384 if id == "" {
385 return false
386 }
387
388 h.applyMu.Lock()
389 defer h.applyMu.Unlock()
390
391 targets := make([]pluginUnloadTarget, 0)
392 h.mu.Lock()
393 lp := h.loaded[id]
394 if lp != nil {
395 targets = append(targets, pluginUnloadTarget{id: lp.id, name: lp.name, path: lp.path, version: lp.version, client: lp.client})
396 }
397 for _, retired := range h.retired[id] {
398 if retired == nil {
399 continue
400 }
401 targets = append(targets, pluginUnloadTarget{id: retired.id, name: retired.name, path: retired.path, version: retired.version, client: retired.client})
402 }
403 if len(targets) == 0 {
404 h.mu.Unlock()
405 return false
406 }
407 delete(h.loaded, id)
408 delete(h.retired, id)
409 delete(h.fused, id)
410 delete(h.activePluginVersions, id)
411 delete(h.activePluginPaths, id)
412 for _, target := range targets {
413 delete(h.pluginFileVersions, cleanPluginPath(target.path))
414 }
415 records, enabled := h.snapshotWithoutPluginLocked(id)
416 h.removePluginRuntimeStateLocked(id)
417 h.snapshot.Store(&Snapshot{enabled: enabled, records: records})
418 h.mu.Unlock()
419
420 h.refreshThinkingProviders(records)
421 h.RegisterFrontendAuthProviders()
422 for _, target := range targets {
423 if target.client != nil {
424 target.client.Shutdown()
425 }
426 log.WithFields(pluginLogFields(target.id, target.name, target.version, target.path)).Info("pluginhost: plugin unloaded")
427 }
428 return true
429}
430
431// ShutdownAll removes active plugin capabilities and closes all loaded dynamic libraries.
432func (h *Host) ShutdownAll() {

Callers

nothing calls this directly

Calls 7

cleanPluginPathFunction · 0.85
pluginLogFieldsFunction · 0.85
ShutdownMethod · 0.65

Tested by

no test coverage detected