OSX crash fix and debugger lost socket fix.

See commit messages for details.