Skip to content

Improve bin/dev kill process management with better error handling #1858

@justin808

Description

@justin808

Improve bin/dev kill Process Management

Background

In the react_on_rails-demos repository, we recently implemented improved process management for watch processes with proper error handling (see PR #42). This same improvement should be applied to the bin/dev kill script in react_on_rails.

Problem

The current process killing logic likely has similar issues to what we found in the demos repo:

  • Counting processes as "killed" even when Process.kill fails due to permission errors (EPERM)
  • Not distinguishing between successful kills, already-stopped processes, and permission-denied errors
  • Potentially confusing user feedback about what actually happened

Solution

Apply the same improved error handling pattern that was implemented in react_on_rails-demos:

Current Pattern (Incorrect)

begin
  Process.kill('TERM', pid)
rescue Errno::ESRCH, Errno::EPERM
  # Treats both cases the same
end
killed_count += 1  # Always increments, even on EPERM!

Improved Pattern

begin
  Process.kill('TERM', pid)
  killed_count += 1
rescue Errno::ESRCH
  # Process already stopped - treat as success
  puts "Process #{pid} - process no longer exists"
  killed_count += 1
rescue Errno::EPERM
  # Permission denied - do NOT count as success
  puts "⚠️  Process #{pid} - permission denied (process owned by another user)"
end

Key Improvements

  1. Accurate counting: Only increment killed_count when kill succeeds or process is already gone (ESRCH)
  2. Clear feedback: Distinguish between:
    • ✅ Successfully killed
    • ✅ Already stopped (ESRCH - treat as success)
    • ⚠️ Permission denied (EPERM - NOT a success)
  3. Better UX: Users know exactly what happened with each process

Reference Implementation

See the complete implementation in react_on_rails-demos:

Testing Checklist

When implementing this fix:

  • Test killing processes you own (should succeed)
  • Test with already-stopped processes (should handle ESRCH gracefully)
  • Test with processes owned by other users (should show EPERM warning and not count as success)
  • Verify final count matches actual successful kills

Related

This is part of broader improvements to process management that were implemented in the demos repository for issue #37.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions