WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@EhabY
Copy link
Collaborator

@EhabY EhabY commented Dec 30, 2025

Summary

  • Clean up old <pid>.json files in the network info directory on monitor start (files older than 1 hour)
  • Search for a new SSH process after 5 consecutive failures to read the network info file (similar to existing stale file behavior)

Details

Network info files (<basePath>/net/<pid>.json) are created by the Coder CLI and persist after processes terminate. This adds automatic cleanup of files not modified in the last hour.

Previously, if the network info file was missing (e.g., deleted or never created), the monitor would log errors indefinitely without attempting to find a new process. Now it behaves consistently with stale file detection - after 5 failures (with delays), it searches for a new SSH process.

Closes #51

- Clean up network info files older than 1 hour when monitoring starts
- Search for new SSH process after 5 consecutive file read failures
@EhabY EhabY force-pushed the delete-old-network-info-files branch from b43d8f1 to dba73e1 Compare December 30, 2025 10:15
Comment on lines +90 to +92
if (!file.endsWith(".json")) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

If each filename corresponds to a PID, we should also validate that the PID is no longer active.

Copy link
Collaborator Author

@EhabY EhabY Dec 30, 2025

Choose a reason for hiding this comment

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

Oooh I like this actually, would mean that we might not need the 1 hour threshold 🤔 ?

I suppose the OS can re-use a PID though so it's not entirely accurate. We can do something like isPidAlive(pid) || isAnHourOld so it's more aggressive though not sure if it's super worth it for a PID check

Copy link
Member

Choose a reason for hiding this comment

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

That's a good point. I guess in the worst case scenario the process would still have the file handle (although deleted)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If the process has a file lock then we might error as EBUSY (or maybe PERM depending on the OS) but in any case that wouldn't cause any issues + we only delete it if it's been untouched in an hour (this is usually updated every ~3 seconds). IMO I do not think a PID check here is worthwhile

Copy link
Member

Choose a reason for hiding this comment

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

If I understand correctly (have not reviewed the code, just based off the description) this would delete logs from active connections? Would make debugging any issue that happens after an hour difficult to diagnose.

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 log file issue can be handled here #377 (rotation with a maximum number of files or maybe date-based etc)

Copy link
Member

Choose a reason for hiding this comment

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

Ahaha this is what I get for not fully reading. But would this break the connection info on the bottom bar for active connections?

Copy link
Member

Choose a reason for hiding this comment

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

Ohhh wait are you checking last modified time, not created?

Copy link
Member

@code-asher code-asher Dec 30, 2025

Choose a reason for hiding this comment

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

Yeah you are lol next time I will just read the code haha. All good from me!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hahaha understandable, I have another PR you can read as well 🙈

@EhabY EhabY requested a review from johnstcn December 30, 2025 16:20
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.

Old JSON files are left in net folder of extension

3 participants