fly logs stops showing new lines after a few seconds, but fly logs --no-tail has them

flyctl v0.4.118, darwin/arm64, app in fra.

To reproduce, tail an app’s logs, then start a Machine that prints one line a second for a minute:

LOG_LEVEL=debug fly logs -a <app> --json

fly machine run alpine:3 -a <app> --region fra --restart no --rm --detach -- \
  sh -c 'for i in $(seq 1 60); do echo tick $i; sleep 1; done'

I tried this three times today. The tail showed ticks 1 to 17 the first time, 1 to 9 the second, and none the third. Each time the fly logs process kept running and printed nothing more. fly logs --no-tail straight after showed all 60 ticks.

The debug output from the third try shows flyctl polling GET /api/v1/apps/<app>/logs?next_token=1792783284795362836 about every 6 seconds. Every answer was {"data":[],"meta":{"next_token":""}}. About two minutes after the Machine finished, I sent the same request with the same next_token by hand and got 74 entries, the ticks among them. So the lines were stored, but the API returned nothing for that position while the tail was asking.

In longer sessions, fly logs also exits on its own every 8 minutes or so, with exit code 0 and no message.

For now we poll fly logs --no-tail every 10 seconds and drop lines we’ve already seen. This may be the same problem as fly logs hangs periodically · Issue #515 · superfly/flyctl · GitHub.

Hi, I just tried this repro and in my case it didn’t miss a beat (or should I say a tick?). Is there something else at play? network shenanigans? something? (for completeness, I’m in Canada and I even used a machine in fra, same as your region - so even transatlantically, it works fine for me).

Hmm, the part about the same next_token returning empty results and then showing 74 entries later is pretty interesting.

I wonder if this is more of a cursor or log availability issue than a network problem.

I’m not entirely sure how the logs API handles empty responses, but maybe the client is treating an empty next_token as a reason to stop advancing, even when more logs become available later.

One thing I’d be curious about is whether the behavior changes when the polling interval is longer. If it does, that might point to a timing issue between log ingestion and the API rather than the connection itself.