Skip to content
This repository was archived by the owner on Jun 2, 2022. It is now read-only.

Commit 43fa128

Browse files
authored
Merge pull request #775 from MikaelSmith/fix-panic
Fix panic when waiting for pod times out
2 parents 72896d6 + 3894c17 commit 43fa128

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

plugin/kubernetes/pvc.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ func (v *pvc) inContainer(ctx context.Context, fn containerCb) (interface{}, err
136136
if err != nil {
137137
return nil, err
138138
}
139+
cleanup = func() {
140+
// Use a background context to ensure deletion happens even if context was cancelled.
141+
activity.Record(ctx, "Deleted temporary pod %v: %v", tempPod, tempPod.delete(context.Background()))
142+
}
139143
if err := tempPod.waitOnCreation(ctx); err != nil {
144+
cleanup()
140145
return nil, err
141146
}
142147
execContainer.pod = tempPod.pod
143-
cleanup = func() {
144-
activity.Record(ctx, "Deleted temporary pod %v: %v", tempPod, tempPod.delete(ctx))
145-
}
146148
} else {
147149
mount := v.getMountInfo(mountingPod, volumeName)
148150
execContainer.pod = mount.pod
@@ -168,15 +170,18 @@ func (v *pvc) exec(ctx context.Context, buildCmd cmdBuilder, stdin io.Reader) ([
168170
streamOpts := remotecommand.StreamOptions{Stdout: &stdout, Stderr: &stderr, Stdin: stdin}
169171
executor, err := c.newExecutor(ctx, cmd[0], cmd[1:], streamOpts)
170172
if err != nil {
171-
return []byte{}, err
173+
return nil, err
172174
}
173175

174176
err = executor.Stream()
175177
activity.Record(ctx, "stdout: %v", stdout.String())
176178
activity.Record(ctx, "stderr: %v", stderr.String())
177179
return stdout.Bytes(), err
178180
})
179-
return obj.([]byte), err
181+
if err != nil {
182+
return nil, err
183+
}
184+
return obj.([]byte), nil
180185
}
181186

182187
func (v *pvc) VolumeList(ctx context.Context, path string) (volume.DirMap, error) {
@@ -226,7 +231,10 @@ func (v *pvc) VolumeStream(ctx context.Context, path string) (io.ReadCloser, err
226231
cleanup()
227232
}}, nil
228233
})
229-
return obj.(io.ReadCloser), err
234+
if err != nil {
235+
return nil, err
236+
}
237+
return obj.(io.ReadCloser), nil
230238
}
231239

232240
func (v *pvc) VolumeWrite(ctx context.Context, path string, b []byte, _ os.FileMode) error {

transport/ssh_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io/ioutil"
1111
"os"
1212
"strconv"
13+
"sync"
1314
"testing"
1415

1516
gssh "github.com/gliderlabs/ssh"
@@ -22,7 +23,9 @@ import (
2223

2324
type SSHTestSuite struct {
2425
suite.Suite
25-
s gssh.Server
26+
s gssh.Server
27+
// Use a mux to avoid identifying a "data race" betweene Handler and SetupTest
28+
mux sync.Mutex
2629
m mock.Mock
2730
knownHosts string
2831
badKnownHosts string
@@ -41,16 +44,22 @@ const (
4144

4245
// Must be mocked for successful connections.
4346
func (suite *SSHTestSuite) Handler(s gssh.Session) {
47+
suite.mux.Lock()
4448
suite.m.Called(s)
49+
suite.mux.Unlock()
4550
}
4651

4752
// Must be mocked if Identity.Password is set.
4853
func (suite *SSHTestSuite) PasswordHandler(ctx gssh.Context, password string) bool {
54+
suite.mux.Lock()
55+
defer suite.mux.Unlock()
4956
return suite.m.Called(ctx, password).Bool(0)
5057
}
5158

5259
// Must be mocked.
5360
func (suite *SSHTestSuite) PublicKeyHandler(ctx gssh.Context, key gssh.PublicKey) bool {
61+
suite.mux.Lock()
62+
defer suite.mux.Unlock()
5463
return suite.m.Called(ctx, key).Bool(0)
5564
}
5665

@@ -125,7 +134,9 @@ func (suite *SSHTestSuite) SetupSuite() {
125134

126135
func (suite *SSHTestSuite) SetupTest() {
127136
// Reset mocks before every test
137+
suite.mux.Lock()
128138
suite.m = mock.Mock{}
139+
suite.mux.Unlock()
129140
}
130141

131142
func (suite *SSHTestSuite) TearDownTest() {

0 commit comments

Comments
 (0)