Skip to content

bitsocial logs -f doesn't see appended lines on Windows #40

@Rinse12

Description

@Rinse12

Bug

On Windows, bitsocial logs -f (follow mode) does not emit new lines that another process appends to the current log file. The CLI emits the initial dump and then sits silent, even after the file size visibly grows.

Linux and macOS behave correctly.

Repro / evidence

The test continues watching old file if no new file appears (test/cli/logs.test.ts:462) reliably fails on Windows in CI:

The assertion:

expected '[2026-05-01T00:00:00.000Z] initial li…' to contain 'APPENDED_LINE'

The test:

  1. Writes an initial line to a log file.
  2. Spawns bitsocial logs -f against it.
  3. After observing the initial line on stdout, appends APPENDED_LINE to the same file.
  4. Expects the CLI to emit APPENDED_LINE within 8 seconds.

On Windows the CLI runs the full 8s without emitting the appended line. Linux and macOS pass.

Root cause

src/cli/commands/logs.ts uses fs.watchFile(currentLogFile, { interval: 300 }, readNewData) to detect new bytes. fs.watchFile is backed by libuv's uv_fs_poll_t. On Windows, this notification mechanism does not reliably fire when another process appends to a file — a long-standing platform gap, documented in nodejs/node#36888 and the original nodejs/node-v0.x-archive#1358.

This is not just a test bug: any Windows user running bitsocial logs -f against a running daemon log file would see the same silence.

Fix

Replace fs.watchFile with a userspace self-rescheduling setTimeout poll that calls fs.promises.stat() + reads new bytes when the size grows. This is the pattern used by production tail-f libraries (@logdna/tail-file, etc.) precisely because OS file-watcher events aren't cross-platform reliable for this scenario. CPU/IO profile is equivalent to the current setup (we were already polling — just inside libuv).

No new dependency; isolated change to src/cli/commands/logs.ts. The existing failing test serves as the regression test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions