Skip to content

Commit 016dab9

Browse files
author
Eddie
authored
fix(Kubernetes client): Log and ignore end of stream exceptions from the Kubernetes API
This is a workaround for a bug in the Kubernetes client. kubernetes-client/csharp#893. It will log and then ignore error messages like `System.Net.Http.HttpRequestException: Error while copying content to a stream.`
1 parent 3f42bbc commit 016dab9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/KubeOps/Operator/Kubernetes/ResourceWatcher{TEntity}.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ private void OnWatcherEvent(WatchEventType type, TEntity resource)
136136
case WatchEventType.Deleted:
137137
_watchEvents.OnNext(new WatchEvent(type, resource));
138138
break;
139+
139140
case WatchEventType.Error:
140141
case WatchEventType.Bookmark:
141142
break;
143+
142144
default:
143145
throw new ArgumentOutOfRangeException(nameof(type), type, "Event did not match.");
144146
}
@@ -164,6 +166,15 @@ e.InnerException is JsonException &&
164166
@"The watcher received an empty response for resource ""{resource}"".",
165167
typeof(TEntity));
166168
return;
169+
170+
// this is a workaround for a bug in the kubernetes client. https://github.com/kubernetes-client/csharp/issues/893
171+
case HttpRequestException hre when
172+
e.InnerException is EndOfStreamException &&
173+
e.InnerException.Message.Contains("Attempted to read past the end of the stream."):
174+
_logger.LogDebug(
175+
@"The watcher received a known error from the watched resource ""{resource}"". This indicates that there are no instances of this resource.",
176+
typeof(TEntity));
177+
return;
167178
}
168179

169180
var backoff = DefaultBackoff;

0 commit comments

Comments
 (0)