state: explicitly free resources on Close()
This commit is contained in:
23
lib/state.go
23
lib/state.go
@@ -54,9 +54,8 @@ type State struct {
|
||||
Mux *http.ServeMux
|
||||
}
|
||||
|
||||
func NewState(p policy.Policy, opt settings.Settings, settings policy.StateSettings) (handler http.Handler, err error) {
|
||||
|
||||
state := new(State)
|
||||
func NewState(p policy.Policy, opt settings.Settings, settings policy.StateSettings) (state *State, err error) {
|
||||
state = new(State)
|
||||
state.close = make(chan struct{})
|
||||
state.settings = settings
|
||||
state.opt = opt
|
||||
@@ -273,3 +272,21 @@ func NewState(p policy.Policy, opt settings.Settings, settings policy.StateSetti
|
||||
|
||||
return state, nil
|
||||
}
|
||||
|
||||
func (state *State) Close() error {
|
||||
select {
|
||||
case <-state.close:
|
||||
default:
|
||||
close(state.close)
|
||||
for _, c := range state.challenges {
|
||||
if c.Object != nil {
|
||||
err := c.Object.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user