{"record":{"id":"4266da94a2dacbb1","repo":"NationalSecurityAgency/ghidra","slug":"could-not-start-server","errorCode":null,"errorMessage":"Could not start server","messagePattern":"Could not start server","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"Ghidra/Debug/Debugger-dap/src/main/java/dap/DapServer.java","lineNumber":63,"sourceCode":"\t\tthis.port = plugin.getPort();\n\t}\n\n\tpublic void startServer() {\n\t\tif (running) {\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tif (server != null && !server.isClosed()) {\n\t\t\t\tserver.close();\n\t\t\t}\n\t\t\tserver = new ServerSocket(port, 50, address);\n\t\t\tthis.running = true;\n\n\t\t\tthis.listenerThread = new Thread(this, \"DAP-Server-Listener\");\n\t\t\tthis.listenerThread.start();\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(\"Could not start server\" + e.getMessage());\n\t\t}\n\t}\n\n\tpublic void stopServer() {\n\t\tif (!running) {\n\t\t\treturn;\n\t\t}\n\t\trunning = false;\n\n\t\tif (server != null) {\n\t\t\ttry {\n\t\t\t\tif (!server.isClosed()) {\n\t\t\t\t\tserver.close();\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tMsg.warn(this, \"Error closing server socket: \" + e.getMessage());\n\t\t\t}","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-dap/src/main/java/dap/DapServer.java#L45-L81","documentation":"DapServer.startServer wraps an IOException from new ServerSocket(port, 50, address) in a RuntimeException('Could not start server' + e.getMessage()). The server socket could not be bound, so the Debug Adapter Protocol listener thread never starts. The cause message is concatenated into the thrown message (no exception chaining, so the stack trace loses the original IOException as a cause).","triggerScenarios":"startServer() is invoked when the requested TCP port is already in use, the bind address is not valid on the host, or the OS refuses the bind (privileged port without permission, or port exhausted). The bind happens before the listener thread is started, so the failure is immediate.","commonSituations":"A previous DAP server instance did not shut down and still holds the port; another application occupies the configured port; trying to bind to a privileged port (<1024) as a non-root user; binding to an address that does not exist on the machine.","solutions":["Free or change the port: pick an unused port for the DAP server before calling startServer().","Ensure a previous DapServer instance was stopped via stopServer() and its ServerSocket closed (check running flag / isClosed).","Use a non-privileged port and bind to a valid local address (e.g. loopback).","If the message is truncated, reproduce with a direct ServerSocket bind to see the real IOException (BindException, etc.)."],"exampleFix":"// before\npublic void startServer() {\n    try {\n        server = new ServerSocket(port, 50, address);\n        ...\n    } catch (IOException e) {\n        throw new RuntimeException(\"Could not start server\" + e.getMessage());\n    }\n}\n\n// after\npublic void startServer() throws IOException {\n    try {\n        server = new ServerSocket(port, 50, address);\n    } catch (IOException e) {\n        throw new IOException(\"Could not start server on \" + address + \":\" + port, e);\n    }\n    ...\n}","handlingStrategy":"try-catch","validationCode":"try (ServerSocket probe = new ServerSocket(port, 50, address)) {\n    // port is free; close probe then let DapServer bind\n} catch (IOException e) {\n    // port unavailable; choose another port before startServer()\n}","typeGuard":null,"tryCatchPattern":"try {\n    server.startServer();\n} catch (RuntimeException e) {\n    // startServer wraps IOException; report bind failure and pick a new port\n}","preventionTips":["Always stopServer() and confirm the socket is closed before restarting.","Pick a high, non-privileged, likely-free port for DAP.","Bind to a valid local address (loopback) to avoid address-related bind failures."],"tags":["network","server","socket","dap","bind"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}