Skip to content

Commit 6b43c7a

Browse files
lpcoxCopilot
andauthored
Update internal/guard/registry.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 995beeb commit 6b43c7a

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

internal/guard/registry.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,23 @@ func (r *Registry) GetGuardInfo() map[string]string {
106106
// Close closes all registered guards that implement Close(context.Context) error.
107107
// It should be called during server shutdown to release WASM runtime resources.
108108
func (r *Registry) Close(ctx context.Context) {
109+
type closableGuard struct {
110+
id string
111+
c interface{ Close(context.Context) error }
112+
}
113+
109114
r.mu.Lock()
110-
defer r.mu.Unlock()
115+
closers := make([]closableGuard, 0, len(r.guards))
111116
for id, g := range r.guards {
112117
if c, ok := g.(interface{ Close(context.Context) error }); ok {
113-
if err := c.Close(ctx); err != nil {
114-
logger.LogWarn("guard", "Failed to close guard for server %s: %v", id, err)
115-
}
118+
closers = append(closers, closableGuard{id: id, c: c})
119+
}
120+
}
121+
r.mu.Unlock()
122+
123+
for _, guard := range closers {
124+
if err := guard.c.Close(ctx); err != nil {
125+
logger.LogWarn("guard", "Failed to close guard for server %s: %v", guard.id, err)
116126
}
117127
}
118128
}

0 commit comments

Comments
 (0)