Choosing Between Local and Remote Debugging in GoLand
Decide between local and remote debugging in GoLand. Learn when to use Delve in containers, how to disable compiler optimizations, and how to validate remote connections.
10 Apr 2026, 06:10 UTC

The Debugging Decision: Local vs. Remote
When a Go application fails, the primary challenge is often reproducing the state. While local debugging is fast, it frequently fails to capture bugs caused by environment-specific configurations, network latency, or container orchestration. The decision rests on whether the bug is logic-based (local) or environment-based (remote).
Comparison of Debugging Modes
| Feature | Local Debugging | Remote Debugging (Delve) |
|---|---|---|
| Setup Speed | Instant (One-click) | Moderate (Requires dlv server) |
| Environment | Host OS / IDE Context | Container / Remote VM |
| Binary Requirements | Managed by GoLand | Manual -gcflags='all=-N -l' |
| Execution Control | Start/Stop/Restart | Attach/Detach to running process |
| Performance | High (Local IPC) | Variable (Network Latency) |
Trade-offs and Constraints
Local Debugging is the default path. GoLand handles the compilation and launches the Delve (dlv) debugger automatically. This is ideal for unit tests and initial feature development. However, it ignores the constraints of your production runtime, such as read-only filesystems or specific kernel versions.
Remote Debugging allows you to attach to a process already running in a container or on a remote server. This is critical for debugging race conditions that only appear under specific load or configuration. The primary trade-off is the optimization penalty: you must compile your binary without optimizations to prevent the compiler from stripping variables or inlining functions, which can slightly alter the timing of the application.
Implementing Remote Debugging in Docker
To debug a containerized Go application, you must run the Delve server inside the container and expose its API port (default 2345).
1. Compile the Binary
Run this command in your CI/CD pipeline or local build script to ensure the debugger can read the variable states. Run this on the machine performing the build:
go build -gcflags="all=-N -l" -o app-debug .
2. Launch Delve in the Container
Start the Delve server in headless mode. This allows GoLand to connect via TCP. Run this inside the container (or via docker exec) with root permissions:
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./app-debug
Risk: Exposing port 2345 to the public internet allows anyone to execute arbitrary code in your process. Ensure this port is only accessible via a VPN or a secure SSH tunnel.
3. Configure GoLand
- Navigate to Run > Edit Configurations.
- Click the + icon and select Go Remote.
- Set Host to the IP address of your container/server.
- Set Port to
2345. - Click OK and select the configuration from the toolbar, then click the Debug (bug) icon.
Validating the Connection
Once connected, verify the state using these three checks:
- Breakpoint Trigger: Set a breakpoint in a frequently hit handler. If the IDE pauses execution, the symbol mapping between your local source code and the remote binary is correct.
- Goroutine Inspection: Open the Debug tool window and check the Goroutines tab. You should see a list of all active concurrent processes; if this list is empty or crashes, the Delve version may be mismatched with the Go version.
- Variable Watch: Hover over a variable during a pause. If you see
<optimized out>, the binary was compiled with optimizations, and you must rebuild using the-gcflagsmentioned above.
Rollback and Cleanup
Because remote debugging requires a specialized binary and an open port, you must revert these changes before deploying to production:
- Stop the Delve server process inside the container.
- Replace the
app-debugbinary with a standard production build (go build -o app .) to restore performance and security. - Close the firewall port 2345.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.