fixed session manager
This commit is contained in:
@ -130,19 +130,33 @@ func (m *Manager) Scrollback(id string) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (m *Manager) DeleteSession(ctx context.Context, id string) error {
|
||||
runtime, err := m.runtimeByID(id)
|
||||
if err != nil {
|
||||
return err
|
||||
m.mu.RLock()
|
||||
runtime, hasRuntime := m.runtimes[id]
|
||||
m.mu.RUnlock()
|
||||
|
||||
var snapshot domain.Session
|
||||
if hasRuntime {
|
||||
snapshot = runtime.Snapshot()
|
||||
} else {
|
||||
stored, ok, err := m.store.Get(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return ErrSessionNotFound
|
||||
}
|
||||
snapshot = stored
|
||||
}
|
||||
|
||||
snapshot := runtime.Snapshot()
|
||||
if snapshot.Status == domain.SessionStatusRunning {
|
||||
return ErrSessionRunning
|
||||
}
|
||||
|
||||
m.mu.Lock()
|
||||
delete(m.runtimes, id)
|
||||
m.mu.Unlock()
|
||||
if hasRuntime {
|
||||
m.mu.Lock()
|
||||
delete(m.runtimes, id)
|
||||
m.mu.Unlock()
|
||||
}
|
||||
|
||||
return m.store.Delete(ctx, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user