Skip to content

Commit a087201

Browse files
committed
Clear c.id on Close to avoid closing twice
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
1 parent 62c321b commit a087201

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

command.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ type Command struct {
3737

3838
done chan struct{}
3939
cancel chan struct{}
40-
once sync.Once
4140
}
4241

4342
func newCommand(ctx context.Context, shell *Shell, ids string) *Command {
@@ -114,24 +113,19 @@ func (c *Command) check() error {
114113

115114
// Close will terminate the running command
116115
func (c *Command) Close() error {
117-
var err error
118-
119-
if err = c.check(); err != nil {
116+
if err := c.check(); err != nil {
120117
return err
121118
}
122119

123-
if _, ok := <-c.cancel; !ok {
124-
return nil // channel already closed, do not send a signal
125-
}
120+
close(c.cancel)
126121

127-
c.once.Do(func() {
128-
close(c.cancel)
122+
id := c.id
123+
c.id = ""
129124

130-
request := NewSignalRequest(c.client.url, c.shell.id, c.id, &c.client.Parameters)
131-
defer request.Free()
125+
request := NewSignalRequest(c.client.url, c.shell.id, id, &c.client.Parameters)
126+
defer request.Free()
132127

133-
_, err = c.client.sendRequest(request)
134-
})
128+
_, err := c.client.sendRequest(request)
135129

136130
return err
137131
}

0 commit comments

Comments
 (0)