Skip to content

Conversation

@marcusrein
Copy link

Summary

Fixes the "Address already in use" error that occurs when AutoSubs doesn't shut down cleanly on macOS.

  • Improves socket binding retry mechanism with up to 3 attempts
  • Sends Exit commands to both server ports during retry
  • Recreates socket on each retry attempt for clean state
  • Adds proper cleanup function and exit handling
  • Includes comprehensive test coverage

Changes

Socket Binding Improvements (AutoSubs V2.lua)

  • Enhanced retry logic with better error handling
  • Sends Exit to both ports (56002 and 55010) during cleanup
  • Recreates socket on each retry to ensure clean state
  • Increases wait time between retries for socket release
  • Adds descriptive error messages for users

Cleanup and Exit Handling

  • New cleanup function ensures proper socket closure
  • Registers cleanup on macOS script termination
  • Handles unexpected exits gracefully

Test Coverage

  • test_socket_fix.lua: Comprehensive test script
  • test_results.md: Documentation showing all tests pass
  • Verifies retry mechanism, cleanup, and error messaging

Test Results

All tests pass successfully:

  • ✅ Socket binding retry mechanism (up to 3 attempts)
  • ✅ Proper cleanup function behavior
  • ✅ Clear error messages for users

Fixes

Closes #199

Users will no longer need to manually kill the Lua process when encountering socket binding errors.

marcusrein and others added 2 commits July 13, 2025 07:42
This commit improves the socket binding mechanism to handle cases where
the AutoSubs Lua server doesn't shut down cleanly, causing the
"Address already in use" error.

Changes:
- Add improved retry mechanism with up to 3 attempts for socket binding
- Send Exit command to both ports (56002 and 55010) during retry
- Recreate socket on each retry attempt to ensure clean state
- Add cleanup function for proper server shutdown
- Register cleanup on exit for macOS to handle script termination
- Increase wait time between retries to allow socket release

This fixes issue tmoroney#199 where users had to manually kill the Lua process
when AutoSubs failed to bind to the port.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
This commit adds comprehensive testing for the socket binding fix:

- test_socket_fix.lua: Test script that simulates the "Address already in use" scenario
- test_results.md: Documentation of test results showing all tests pass

The tests verify:
1. Socket binding retry mechanism (up to 3 attempts)
2. Proper cleanup function behavior
3. Clear error messages for users

All tests pass, confirming the fix successfully resolves issue tmoroney#199.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
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.

[Mac] Address already in Use / No Timeline Detected

1 participant