Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/test/integration/watchPods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default async function watchPods() {
pod.spec = {
containers: [{ name: 'test', image: 'busybox', command: ['sleep', '3600'] }],
restartPolicy: 'Never',
terminationGracePeriodSeconds: 0,
};
await coreV1Client.createNamespacedPod({ namespace, body: pod });

Expand Down
14 changes: 8 additions & 6 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ export class Watch {

if (response.status === 200) {
const body = Readable.fromWeb(response.body! as any);

body.on('error', doneCallOnce);
body.on('close', () => doneCallOnce(null));
body.on('finish', () => doneCallOnce(null));

const lines = createInterface(body);

// Only listen for completion/error on `lines`, not on `body`.
// Listening on `body` can trigger premature close before `lines`
// has finished processing buffered data, which causes
// controller.abort() to fire too early. With undici >= 8.6.0
// this leads to remaining response chunks being dropped.
lines.on('error', doneCallOnce);
lines.on('close', () => doneCallOnce(null));
lines.on('finish', () => doneCallOnce(null));
lines.on('line', (line) => {
try {
const data = JSON.parse(line.toString());
Expand All @@ -86,6 +86,8 @@ export class Watch {
// ignore parse errors
}
});

body.on('error', doneCallOnce);
} else {
const statusText =
response.statusText || STATUS_CODES[response.status] || 'Internal Server Error';
Expand Down