Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error resolving url: Get "http://127.0.0.1:9222/json/version": dial tcp 127.0.0.1:9222: connect: connection refused 0xc000431560 #53

Open
TrueNix opened this issue Apr 3, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@TrueNix
Copy link

TrueNix commented Apr 3, 2024

When I ask to navigate to some page.

Trying to get content from https://{reducted}/
2024/04/03 10:44:32 failed to process browser: %!w(*fmt.wrapError=&{failed to get content: Error loading page: Error resolving url: Get "http://127.0.0.1:9222/json/version": dial tcp 127.0.0.1:9222: connect: connection refused 0xc000431560})

Running from VM tried in bridge as well.

@semanser
Copy link
Owner

semanser commented Apr 3, 2024

This can happen if it can't reach the browser (which is running in a docker container). Could you run docker ps to make sure that it's running?

@TrueNix
Copy link
Author

TrueNix commented Apr 3, 2024

`2024/04/03 11:59:33 OK 20240325154630_initial_migration.sql (3.38ms)
2024/04/03 11:59:33 OK 20240325193843_add_logs_table.sql (9.06ms)
2024/04/03 11:59:33 OK 20240328114536_tool_call_id_field.sql (1.17ms)
2024/04/03 11:59:33 goose: successfully migrated database to version: 20240328114536
2024/04/03 11:59:33 Migrations ran successfully
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.

  • using env: export GIN_MODE=release
  • using code: gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET /graphql --> github.com/semanser/ai-coder/router.graphqlHandler.func4 (5 handlers)
[GIN-debug] POST /graphql --> github.com/semanser/ai-coder/router.graphqlHandler.func4 (5 handlers)
[GIN-debug] PUT /graphql --> github.com/semanser/ai-coder/router.graphqlHandler.func4 (5 handlers)
[GIN-debug] PATCH /graphql --> github.com/semanser/ai-coder/router.graphqlHandler.func4 (5 handlers)
[GIN-debug] HEAD /graphql --> github.com/semanser/ai-coder/router.graphqlHandler.func4 (5 handlers)
[GIN-debug] OPTIONS /graphql --> github.com/semanser/ai-coder/router.graphqlHandler.func4 (5 handlers)
[GIN-debug] DELETE /graphql --> github.com/semanser/ai-coder/router.graphqlHandler.func4 (5 handlers)
[GIN-debug] CONNECT /graphql --> github.com/semanser/ai-coder/router.graphqlHandler.func4 (5 handlers)
[GIN-debug] TRACE /graphql --> github.com/semanser/ai-coder/router.graphqlHandler.func4 (5 handlers)
[GIN-debug] GET /playground --> github.com/semanser/ai-coder/router.New.playgroundHandler.func3 (5 handlers)
[GIN-debug] GET /terminal/:id --> github.com/semanser/ai-coder/router.New.wsHandler.func4 (5 handlers)
[GIN-debug] GET /browser/*filepath --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (5 handlers)
[GIN-debug] HEAD /browser/*filepath --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (5 handlers)
2024/04/03 11:59:33 Docker client initialized: truenix-virtual-machine
2024/04/03 11:59:33 Spawning container ghcr.io/go-rod/rod "codel-browser"
2024/04/03 11:59:33 Image ghcr.io/go-rod/rod found locally: true
2024/04/03 11:59:33 Creating container codel-browser...
2024/04/03 11:59:33 Container not found. Marking it as stopped.
2024/04/03 11:59:33 failed to initialize browser container: failed to spawn container: Error creating container: Error response from daemon: Conflict. The container name "/codel-browser" is already in use by container "11021dbeb4ed0f35579b4606078f64d4f03265527f6de62f7ca3ae8db3892d39". You have to remove (or rename) that container to be able to reuse that name.
`
That happened after reboot the machine

@TrueNix
Copy link
Author

TrueNix commented Apr 3, 2024

i've ran sudo docker container prune now it started:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
711173e27a59 ghcr.io/go-rod/rod "dumb-init -- chrome…" About a minute ago Up About a minute 0.0.0.0:9222->9222/tcp codel-browser
f43736519917 ghcr.io/semanser/codel:latest "/bin/sh -c /app" About a minute ago Up About a minute 0.0.0.0:3000->8080/tcp, :::3000->8080/tcp modest_matsumoto

2024/04/03 12:08:26 Spawning container debian:latest "codel-terminal-1"
2024/04/03 12:08:26 Image debian:latest found locally: true
2024/04/03 12:08:26 Creating container codel-terminal-1...
2024/04/03 12:08:26 Container codel-terminal-1 created
2024/04/03 12:08:26 Container codel-terminal-1 started
2024/04/03 12:08:26 Getting next task
2024/04/03 12:08:31 Command 2 added to the queue 1
2024/04/03 12:08:31 Waiting for a task
2024/04/03 12:08:31 Processing command 2 of type browser
2024/04/03 12:08:31 Trying to get content from https://{reducted}.com/
2024/04/03 12:08:31 failed to process browser: %!w(*fmt.wrapError=&{failed to get content: Error loading page: Error resolving url: Get "http://127.0.0.1:9222/json/version": dial tcp 127.0.0.1:9222: connect: connection refused 0xc0002e2040})
2024/04/03 12:08:31 Waiting for a task

@TrueNix
Copy link
Author

TrueNix commented Apr 3, 2024

curl http://127.0.0.1:9222/json/version from the VM:
{
"Browser": "HeadlessChrome/114.0.5720.0",
"Protocol-Version": "1.3",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/114.0.5720.0 Safari/537.36",
"V8-Version": "11.4.118",
"WebKit-Version": "537.36 (@de21fd13ee1dbfb5c6056aa0220cf1b7f1e750d0)",
"webSocketDebuggerUrl": "ws://127.0.0.1:9222/devtools/browser/4ce8ee7d-0ccc-4855-a037-4eb9e0167523"
}

curl http://127.0.0.1:9222/json/version from the docker

curl: (7) Failed to connect to 127.0.0.1 port 9222 after 0 ms: Couldn't connect to server

@semanser
Copy link
Owner

semanser commented Apr 3, 2024

So you're running: Host -> VM -> Docker.

I suspect that running curl from the Docker is trying to bypass the VM and reach the host somehow.

@TrueNix
Copy link
Author

TrueNix commented Apr 3, 2024

Host -> VM -> Docker

exactly, VM configured as bridge btw

@semanser semanser added the bug Something isn't working label Apr 4, 2024
@semanser
Copy link
Owner

semanser commented Apr 4, 2024

What command did you use to run Codel? Did you use --network="host" by any chance? This could cause it not to work.

@TrueNix
Copy link
Author

TrueNix commented Apr 4, 2024

What command did you use to run Codel? Did you use --network="host" by any chance? This could cause it not to work.

sudo docker run --env-file .env -p 3000:8080 -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/semanser/codel:latest

@timethy96
Copy link

I do not think that the dbus error has something to do with it, as this is a common warning on headless setups.
Also I can curl the /json/version path from inside the go-rod docker container.

So this must be a port forwarding problem.
Apparently there is a vivid discussion about the chrome "--remote-debugging-address" flag that should be deprecated and removed. This would mean that chrome browser only binds to the internal localhost address, not allowing connections from 0.0.0.0, which is needed for Dockers port forwarding mechanism. I guess this is what happened, but curiously not for everyone.

As a (really bad) workaround I changed the line in backend/executor/browser.go spawning the browser container to install and run socat, proxying the local port to 0.0.0.0.

[...]
const port = "9222"
const portInternal = "9223"
[...]
Cmd: []string{"/bin/sh", "-c", fmt.Sprintf("apt update && apt install -y socat && socat TCP-LISTEN:%s,fork TCP:127.0.0.1:%s & chrome --headless --no-sandbox --remote-debugging-port=%s", port, portInternal, portInternal)},
[...]

This gives me the ability to curl from the host, outside the container.
But still I cannot connect to the codel-browser from inside the main codel container...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants