edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Deno + EdgeDB solution issue

Open Stoffberg opened this issue 3 years ago • 9 comments

I'm trying to use Deno and EdgeDB together in a new framework called Fresh, but I'm running into the TLS issue EdgeDB-Deno. After reading the solution proposed, I'm still not able to connect to the client.

I think I am doing something wrong, but not sure what. Can you maybe offer a more in depth explanation or an example I can follow?

Some direction would be helpful. Best regards

Stoffberg avatar Jun 29 '22 18:06 Stoffberg

cc @jaclarke

1st1 avatar Jun 29 '22 23:06 1st1

The readme was out of date (I've just updated it now). Deno now supports tls alpn (behind the --unstable flag), so you shouldn't need to set any edgedb server flags anymore for edgedb-deno to work.

I've just tried out deno's Fresh framework, following the getting started instructions (https://fresh.deno.dev/#getting-started), and for me it works with edgedb-deno by just adding the --unstable flag to the 'start' task.

jaclarke avatar Jun 30 '22 12:06 jaclarke

https://github.com/edgedb/edgedb-examples/issues/76

jaclarke avatar Jun 30 '22 13:06 jaclarke

There must be something fundamental I'm missing, because after adding the --unstable flag to my deno.json like this:

{
  "tasks": {
    "start": "deno run -A --watch=static/,routes/ --unstable dev.ts"
  },
  "importMap": "./import_map.json"
}

having my index.tsx file like this:

/** @jsx h */
import { h } from "preact";
import { tw } from "@twind";
import { Handlers, PageProps } from "https://deno.land/x/[email protected]/server.ts";
import * as edgedb from "https://deno.land/x/[email protected]/mod.ts";

export const handler: Handlers = {
  async GET(_, ctx) {
    const client = edgedb.createClient();

    const result = await client.query(`select 2 + 2;`);

    return ctx.render(result);
  },
};

export default function Home({ data }: PageProps) {
  console.log(data);
}

I still get this error:

A client connection error occurred; reconnecting because of "waitUntilAvailable=30000". ClientConnectionClosedError: network error: ConnectionRefused: No connection could be made because the target machine actively refused it. (os error 10061)
    at RawConnection._onError (https://deno.land/x/[email protected]/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/[email protected]/node/events.ts:167:20)
    at https://deno.land/x/[email protected]/_src/adapter.deno.ts:273:16

Can you give me any direction on what I'm doing wrong? @jaclarke

Stoffberg avatar Jun 30 '22 19:06 Stoffberg

That looks like it should work, it's pretty much the same as my quick test that worked. Can you check what version of EdgeDB you're using and that it's running with the edgedb instance list command? Also I've pushed my example here: https://github.com/jaclarke/edgedb-fresh, if you want to try that.

jaclarke avatar Jun 30 '22 20:06 jaclarke

I have the same issue...

I've copied and ran your example repo (https://github.com/jaclarke/edgedb-fresh), then I've setup the edgedb instance (I have some problems with edgedb project init, so I have to manually link the instance beforehand)

❯ edgedb instance link my_instance
Specify the host of the server [default: localhost]: 
> localhost
Specify the port of the server [default: 5656]: 
> 5656
Specify the database user [default: edgedb]: 
> edgedb
Specify the database name [default: edgedb]: 
> edgedb
Unknown server certificate: SHA1:1c1a7316d61923b5ea101bed65eb0c7770d60097. Trust? [y/N]
> y
/home/lollo/.config/edgedb/credentials/my_instance.json exists! Overwrite? (type `Yes`)
> Yes
Successfully linked to remote instance. To connect run:
  edgedb -I my_instance

edgedb-fresh on  main via 🦕 v1.23.0 via  via ❄️  impure (shell) took 5s 
❯ edgedb project init
Found `edgedb.toml` in /home/lollo/redacted/edgedb-fresh
Initializing project...
Specify the name of EdgeDB instance to use with this project [default: edgedb_fresh]: 
> my_instance
Do you want to use existing instance "my_instance" for the project? [y/n]
> y
Applying migrations...
Everything is up to date. Revision initial
Project linked
To connect to my_instance, run `edgedb`

Running deno task start and browsing the index page results in the ~~same~~ similar issue

A client connection error occurred; reconnecting because of "waitUntilAvailable=30000". ClientConnectionClosedError: network error: InvalidData: invalid peer certificate encoding
    at RawConnection._onError (https://deno.land/x/[email protected]/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/[email protected]/node/events.ts:167:20)
    at https://deno.land/x/[email protected]/_src/adapter.deno.ts:273:16

Info:

  • EdgeDB: running in a container, exposed on localhost, latest version as of 2022-06-30, 1.4+ffe1237.
  • OS: NixOS, using the client downloaded from the edgedb website, EdgeDB CLI 1.1.2+58eb29e

ranfdev avatar Jun 30 '22 21:06 ranfdev

Here is the whole example installation process, with the problem attached: @jaclarke I'm starting to think it might be a access or firewall issue, since it worked for you

This was run with administrator rights

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS D:\Builds> git clone https://github.com/jaclarke/edgedb-fresh.git blog-fresh-edgedb-with-example
Cloning into 'blog-fresh-edgedb-with-example'...
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 30 (delta 6), reused 30 (delta 6), pack-reused 0
Receiving objects: 100% (30/30), 8.89 KiB | 827.00 KiB/s, done.
Resolving deltas: 100% (6/6), done.
PS D:\Builds> cd .\blog-fresh-edgedb-with-example\
PS D:\Builds\blog-fresh-edgedb-with-example> edgedb project init
Found `edgedb.toml` in \\?\D:\Builds\blog-fresh-edgedb-with-example
Initializing project...
Specify the name of EdgeDB instance to use with this project [default: blog_fresh_edgedb_with_example]:
> blog_fresh_edgedb_with_example
Do you want to start instance automatically on login? [y/n]
> y
Checking EdgeDB versions...
┌────────────────────────┬──────────────────────────────────────────────────────────┐
│ Project directory      │ \\?\D:\Builds\blog-fresh-edgedb-with-example             │
│ Project config         │ \\?\D:\Builds\blog-fresh-edgedb-with-example\edgedb.toml │
│ Schema dir (non-empty) │ \\?\D:\Builds\blog-fresh-edgedb-with-example\dbschema    │
│ Installation method    │ WSL                                                      │
│ Start configuration    │ auto                                                     │
│ Version                │ 1.4+5ffe34b                                              │
│ Instance name          │ blog_fresh_edgedb_with_example                           │
└────────────────────────┴──────────────────────────────────────────────────────────┘
Version 1.4+5ffe34b is already installed
Initializing EdgeDB instance...
Applying migrations...
Everything is up to date. Revision initial
Project initialized.
To connect to blog_fresh_edgedb_with_example, run `edgedb`
PS D:\Builds\blog-fresh-edgedb-with-example> deno task start
Warning deno task is unstable and may drastically change in the future
Task start deno run -A --unstable --watch=static/,routes/ dev.ts
Watcher Process started.
Watcher File change detected! Restarting!
Server listening on http://localhost:8000
A client connection error occurred; reconnecting because of "waitUntilAvailable=30000". ClientConnectionClosedError: network error: ConnectionRefused: No connection could be made because the target machine actively refused it. (os error 10061)
    at RawConnection._onError (https://deno.land/x/[email protected]/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/[email protected]/node/events.ts:167:20)
    at https://deno.land/x/[email protected]/_src/adapter.deno.ts:273:16
A client connection error occurred; reconnecting because of "waitUntilAvailable=30000". ClientConnectionClosedError: network error: ConnectionRefused: No connection could be made because the target machine actively refused it. (os error 10061)
    at RawConnection._onError (https://deno.land/x/[email protected]/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/[email protected]/node/events.ts:167:20)
    at https://deno.land/x/[email protected]/_src/adapter.deno.ts:273:16
A client connection error occurred; reconnecting because of "waitUntilAvailable=30000". ClientConnectionClosedError: network error: ConnectionRefused: No connection could be made because the target machine actively refused it. (os error 10061)
    at RawConnection._onError (https://deno.land/x/[email protected]/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/[email protected]/node/events.ts:167:20)
    at https://deno.land/x/[email protected]/_src/adapter.deno.ts:273:16
A client connection error occurred; reconnecting because of "waitUntilAvailable=30000". ClientConnectionClosedError: network error: ConnectionRefused: No connection could be made because the target machine actively refused it. (os error 10061)
    at RawConnection._onError (https://deno.land/x/[email protected]/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/[email protected]/node/events.ts:167:20)
    at https://deno.land/x/[email protected]/_src/adapter.deno.ts:273:16
An error occured during route handling or page rendering. ClientConnectionClosedError: network error: ConnectionRefused: No connection could be made because the target machine actively refused it. (os error 10061)
    at RawConnection._onError (https://deno.land/x/[email protected]/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/[email protected]/node/events.ts:167:20)
    at https://deno.land/x/[email protected]/_src/adapter.deno.ts:273:16
A client connection error occurred; reconnecting because of "waitUntilAvailable=30000". ClientConnectionClosedError: network error: ConnectionRefused: No connection could be made because the target machine actively refused it. (os error 10061)
    at RawConnection._onError (https://deno.land/x/[email protected]/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/[email protected]/node/events.ts:167:20)
    at https://deno.land/x/[email protected]/_src/adapter.deno.ts:273:16
PS D:\Builds\blog-fresh-edgedb-with-example> edgedb instance list
┌───────┬────────────────────────────────────────┬───────┬─────────────┬─────────┐
│ Kind  │ Name                                   │ Port  │ Version     │ Status  │
├───────┼────────────────────────────────────────┼───────┼─────────────┼─────────┤
│ local │ blog_fresh_edgedb                      │ 10700 │ 1.4+5ffe34b │ running │
│ local │ blog_fresh_edgedb_with_example         │ 10702 │ 1.4+5ffe34b │ running │
│ local │ blog_fresh_edgedb_without_autostart_tw │ 10701 │ 1.4+5ffe34b │ running │
└───────┴────────────────────────────────────────┴───────┴─────────────┴─────────┘
PS D:\Builds\blog-fresh-edgedb-with-example>

Thank you for the help, it is really appreciated!

Stoffberg avatar Jul 01 '22 05:07 Stoffberg

Ah right, I can reproduce the problem now (before I was running edgedb and deno both inside wsl).

It seems on windows, Deno is resolving localhost to the ipv6 address ::1, and edgedb server by default only listens on 127.0.0.1 (and on wsl it seems to resolve to 127.0.0.1, which is why it was working for me). Configuring edgedb to also listen on ::1 should fix the problem: edgedb configure set listen_addresses 127.0.0.1 ::1 (https://www.edgedb.com/docs/reference/configuration#configuring-the-server)

jaclarke avatar Jul 04 '22 13:07 jaclarke

Ah right, I can reproduce the problem now (before I was running edgedb and deno both inside wsl).

It seems on windows, Deno is resolving localhost to the ipv6 address ::1, and edgedb server by default only listens on 127.0.0.1 (and on wsl it seems to resolve to 127.0.0.1, which is why it was working for me). Configuring edgedb to also listen on ::1 should fix the problem: edgedb configure set listen_addresses 127.0.0.1 ::1 (https://www.edgedb.com/docs/reference/configuration#configuring-the-server)

can confirm this solves the issue on linux (not wsl)

Tricked-dev avatar Jul 28 '22 15:07 Tricked-dev

I'm using vite-node on linux and it suffers from the same problem. Making edgedb listen on ::1 fixes the problem.

thorstenweber83 avatar Apr 24 '23 20:04 thorstenweber83