Skip to content

Conversation

@EhabY
Copy link
Collaborator

@EhabY EhabY commented Jan 20, 2026

Summary

  • Adds cleanup for proxy log files (coder-ssh-*.log) in the proxy log directory
  • Only triggers when file count exceeds 20 AND oldest files are more than 7 days old
  • Deletes oldest stale files (by mtime) to bring count back to 20
  • Runs on monitor start alongside existing network info file cleanup

Fixed #377

@EhabY EhabY self-assigned this Jan 20, 2026
Clean up old coder-ssh-*.log files when count exceeds 20 and files are
older than 7 days. Uses mtime-based sorting to delete oldest stale files first.
@EhabY EhabY force-pushed the cleanup-old-log-files branch from 25684d1 to 128754a Compare January 20, 2026 14:38
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍 for writing tests

const stats = await fs.stat(path.join(logDir, name));
return { name, mtime: stats.mtime.getTime() };
} catch {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is any weird permission denied error, wouldn't this be an issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be swallowed yes, I'm not sure I wanna log these 🤔

const now = Date.now();
const files = await fs.readdir(logDir);

const withStats = await Promise.all(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that in a typical setup, we will have max 20 log files? no way we will need a handle 100+ = 100 x fs.stat in parallel

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files themselves have timestamps in the name, would it make sense to delete based on the filename only? They are named based on the creation but not necessarily when they were last modified so that's why I settled for this. Potentially we can just sort, delete until there's 20 left

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coder.coder-remote/log can grow quite large

2 participants