Skip to content

Commit 068e717

Browse files
committed
fix: partial line handling in docker events listener
Improves the handling of stdout data from the docker events process by buffering incomplete lines and only processing complete lines. This prevents errors when event data arrives in chunks that do not align with line boundaries.
1 parent 304f1f4 commit 068e717

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/utils/container-status.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,16 @@ function listenToContainerStatus(
130130
throw new Error("Failed to get stdout from docker events process");
131131
}
132132

133+
let buffer = "";
133134
dockerEvents.stdout.on("data", (data: Buffer) => {
134-
const lines = data.toString().split("\n").filter(Boolean);
135-
for (const line of lines) {
135+
buffer += data.toString();
136+
137+
// Process all complete lines
138+
let newlineIndex = buffer.indexOf("\n");
139+
while (newlineIndex !== -1) {
140+
const line = buffer.substring(0, newlineIndex).trim();
141+
buffer = buffer.substring(newlineIndex + 1);
142+
136143
const json = safeJsonParse(line);
137144
const parsed = DockerEventsSchema.safeParse(json);
138145
if (!parsed.success) {
@@ -154,6 +161,8 @@ function listenToContainerStatus(
154161
onStatusChange("stopped");
155162
break;
156163
}
164+
165+
newlineIndex = buffer.indexOf("\n");
157166
}
158167
});
159168
} catch (error) {

0 commit comments

Comments
 (0)