mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Fix regression for timed-out stream cleanups
If a stream is already timed-out, then either the data or error stream may be `nil`. This would cause a segmentation fault, which is now covered with this patch. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
This commit is contained in:
parent
cf1e939ce5
commit
f2ca9c1794
@ -123,7 +123,10 @@ func (c *connection) Close() error {
|
|||||||
func (c *connection) RemoveStreams(streams ...httpstream.Stream) {
|
func (c *connection) RemoveStreams(streams ...httpstream.Stream) {
|
||||||
c.streamLock.Lock()
|
c.streamLock.Lock()
|
||||||
for _, stream := range streams {
|
for _, stream := range streams {
|
||||||
delete(c.streams, stream.Identifier())
|
// It may be possible that the provided stream is nil if timed out.
|
||||||
|
if stream != nil {
|
||||||
|
delete(c.streams, stream.Identifier())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.streamLock.Unlock()
|
c.streamLock.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -323,6 +323,9 @@ func TestConnectionRemoveStreams(t *testing.T) {
|
|||||||
// remove all existing
|
// remove all existing
|
||||||
c.RemoveStreams(stream0, stream1)
|
c.RemoveStreams(stream0, stream1)
|
||||||
|
|
||||||
|
// remove nil stream should not crash
|
||||||
|
c.RemoveStreams(nil)
|
||||||
|
|
||||||
if len(c.streams) != 0 {
|
if len(c.streams) != 0 {
|
||||||
t.Fatalf("should not have any streams, has %d", len(c.streams))
|
t.Fatalf("should not have any streams, has %d", len(c.streams))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user