Repository navigation
Call the log consumer again when a container is restarted - #1665
yabdelhamed wants to merge 2 commits into
Conversation
cristianrgreco
left a comment
There was a problem hiding this comment.
Thanks for the fix and the red-green evidence. I also checked that the new test fails when since is dropped, so it covers the no-replay part too.
- Share the log consumer and internal logger setup between start and restart instead of adding a second copy (inline).
Nits inline.
| const mappedInspectResult = mapInspectResult(this.inspectResult); | ||
| const startTime = new Date(this.inspectResult.State.StartedAt); | ||
|
|
||
| if (this.logConsumer !== undefined) { |
There was a problem hiding this comment.
This repeats GenericContainer.consumeContainerLogs, so start and restart each have their own copy of the consumer and internal logger setup. Move consumeContainerLogs into its own file, like inspectContainerUntilPortsExposed, with an optional since, and call it from startContainer and here.
| expect((await container.exec(["cat", "config.txt"])).output).toEqual(expect.stringContaining("testconfig")); | ||
| }); | ||
|
|
||
| it("should keep streaming logs to the log consumer after restart", async () => { |
There was a problem hiding this comment.
Nit: generic-container-logs.test.ts already has the log consumer test and the internal logger after restart test, so this belongs next to them.
| await container.restart(); | ||
|
|
||
| await vi.waitFor(() => expect(lines.filter((l) => l.includes("Listening on port 8080"))).toHaveLength(2), { | ||
| timeout: 10_000, |
There was a problem hiding this comment.
Nit: the consumer's stream is open before restart() waits for the container, so the default waitFor timeout is enough here, as in the first waitFor.
Summary
restart()reattaches the internal container logger, but not the consumer fromwithLogConsumer. The consumer's stream ends when the container stops and nothing replaces it, so it gets no output after the restart.StartedGenericContainernow gets the consumer fromGenericContainer(on both the start and the reuse path) and calls it again inrestart()with a new stream, using the samesinceas the internal logger, so lines from before the restart aren't replayed. Go keeps log consumers across stop/start too.The log consumer docs now say what happens on restart.
Closes #1663
Verification
Red-green: new "should keep streaming logs to the log consumer after restart" in
generic-container-restart.test.ts. Before the fix:expected [ 'Listening on port 8080\n' ] to have a length of 2 but got 1.The scenario from the issue, an alpine container printing
tick Nevery second, restarted after 3.5s:after: []after: ["boot","tick 1","tick 2","tick 3","tick 4","tick 5"], nothing from the first run repeatedRuns:
npx vitest runon the restart, logs and reuse tests anddocker-compose-environment: 47 passed.should work with buildkitfails locally because I don't have the buildx plugin installed; it doesn't touch this code.biome ci --error-on-warnings,npm run knip,npm run check-compiles: clean.