{"id":13567348,"url":"https://github.com/square/debug_socket","last_synced_at":"2025-06-13T01:39:38.174Z","repository":{"id":10652873,"uuid":"62245239","full_name":"square/debug_socket","owner":"square","description":"Debug socket.","archived":false,"fork":false,"pushed_at":"2022-10-17T18:27:06.000Z","size":35,"stargazers_count":9,"open_issues_count":1,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-06T16:49:44.702Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/square.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-29T17:36:03.000Z","updated_at":"2023-04-29T04:01:35.000Z","dependencies_parsed_at":"2022-08-07T06:00:10.929Z","dependency_job_id":null,"html_url":"https://github.com/square/debug_socket","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fdebug_socket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fdebug_socket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fdebug_socket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fdebug_socket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/square","download_url":"https://codeload.github.com/square/debug_socket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247107816,"owners_count":20884793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:02:29.049Z","updated_at":"2025-04-04T01:31:42.524Z","avatar_url":"https://github.com/square.png","language":"Ruby","readme":"# DebugSocket\n\nA unix domain socket that listens for debug commands.\n\n[![Build Status](https://travis-ci.org/square/debug_socket.svg?branch=master)](https://travis-ci.org/square/debug_socket)\n\n## Warning\n\nAnything sent to the unix domain socket will be passed to `eval()`. Be careful.\nSecurity-wise, this is OK: the debug socket is restricted to the process owner.\nThe socket permissions are 0600, so only the user running the process can\nconnect to the socket. The user that is running the process can also attach GDB\nto the running process and do the same things the socket allows, only it won't\nbe memory safe ;).\n\n\n## Usage\n\nA rails example with puma and sidekiq:\n\nin `config/puma.rb`\n\n```ruby\non_worker_boot do\n  DebugSocket.logger = Rails.logger\n  DebugSocket.start(Rails.root.join(\"tmp\", \"puma-debug-#{Process.pid}.sock\"))\nend\n\non_worker_shutdown do\n  DebugSocket.stop\nend\n```\n\nin `config/initializers/sidekiq.rb`\n\n```ruby\nSidekiq.configure_server do |_config|\n  DebugSocket.logger = Sidekiq::Logging.logger\n  # GOTCHA: if the Rails.root.join(\"tmp\", \"sidekiq-debug-#{Process.pid}.sock\")\n  # path is too long, this will fail. The max on Linux is 108 characters, MacOS\n  # is 104. If the path is too long, try using a relative path or /tmp/\u003cblah\u003e.\n  DebugSocket.start(Rails.root.join(\"tmp\", \"sidekiq-debug-#{Process.pid}.sock\"))\n  at_exit { DebugSocket.stop }\nend\n```\n\nYou can now send ruby instruction commands through the socket and they'll be\nexecuted in your running process.  You can use `socat` to write and read\nfrom the socket and dump to `stdout` like so:\n\n```\n% echo backtrace | socat - UNIX-CONNECT:~/tmp/puma-debug-1234.sock\n2016-08-09T00:51:57Z puma: cluster worker 0: 1234\n2016-08-09T00:51:57Z pid=1234 thread.object_id=70099243629020 thread.status=run\nlib/debug_socket.rb:55:in `backtrace'\nlib/debug_socket.rb:55:in `block in backtrace'\nlib/debug_socket.rb:54:in `map'\nlib/debug_socket.rb:54:in `backtrace'\nspec/debug_socket_spec.rb:48:in `block (3 levels) in \u003ctop (required)\u003e'\n\n2016-08-09T00:51:57Z pid=1234 thread.object_id=70121809360520 thread.status=sleep\nspec/debug_socket_spec.rb:48:in `sleep'\nspec/debug_socket_spec.rb:48:in `block (4 levels) in \u003ctop (required)\u003e'\n```\n\nThe gem also provides a script.  The `debug-socket` script takes one argument,\nthe path to the unix socket, and it will run the `backtrace` command through\nthat socket.\n\n```\n% debug-socket ~/tmp/puma-debug-1234.sock\n2016-08-09T00:51:57Z puma: cluster worker 0: 1234\n2016-08-09T00:51:57Z pid=1234 thread.object_id=70099243629020 thread.status=run\nlib/debug_socket.rb:55:in `backtrace'\nlib/debug_socket.rb:55:in `block in backtrace'\nlib/debug_socket.rb:54:in `map'\nlib/debug_socket.rb:54:in `backtrace'\nspec/debug_socket_spec.rb:48:in `block (3 levels) in \u003ctop (required)\u003e'\n\n2016-08-09T00:51:57Z pid=1234 thread.object_id=70121809360520 thread.status=sleep\nspec/debug_socket_spec.rb:48:in `sleep'\nspec/debug_socket_spec.rb:48:in `block (4 levels) in \u003ctop (required)\u003e'\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/square/debug_socket.\n\nIf you would like to contribute code to DebugSocket, thank you! You can do so\nthrough GitHub by forking the repository and sending a pull request. However,\nbefore your code can be accepted into the project we need you to sign Square's\n(super simple) [Individual Contributor License Agreement\n(CLA)](https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ\u0026ndplr=1)\n\n## License\n\n    Copyright 2016 Square, Inc.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fdebug_socket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquare%2Fdebug_socket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fdebug_socket/lists"}