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

Deno + EdgeDB solution issue #376

Open
Stoffberg opened this issue Jun 29, 2022 · 10 comments
Open

Deno + EdgeDB solution issue #376

Stoffberg opened this issue Jun 29, 2022 · 10 comments

Comments

@Stoffberg
Copy link

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

@1st1
Copy link
Member

1st1 commented Jun 29, 2022

cc @jaclarke

@jaclarke
Copy link
Member

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
Copy link
Member

@Stoffberg Stoffberg reopened this Jun 30, 2022
@Stoffberg
Copy link
Author

Stoffberg commented Jun 30, 2022

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/fresh@1.0.0/server.ts";
import * as edgedb from "https://deno.land/x/edgedb@v0.20.10/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/edgedb@v0.20.10/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/std@0.114.0/node/events.ts:167:20)
    at https://deno.land/x/edgedb@v0.20.10/_src/adapter.deno.ts:273:16

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

@jaclarke
Copy link
Member

jaclarke commented Jun 30, 2022

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.

@ranfdev
Copy link

ranfdev commented Jun 30, 2022

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/edgedb@v0.20.10/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/std@0.114.0/node/events.ts:167:20)
    at https://deno.land/x/edgedb@v0.20.10/_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

@Stoffberg
Copy link
Author

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/edgedb@v0.20.10/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/std@0.114.0/node/events.ts:167:20)
    at https://deno.land/x/edgedb@v0.20.10/_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/edgedb@v0.20.10/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/std@0.114.0/node/events.ts:167:20)
    at https://deno.land/x/edgedb@v0.20.10/_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/edgedb@v0.20.10/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/std@0.114.0/node/events.ts:167:20)
    at https://deno.land/x/edgedb@v0.20.10/_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/edgedb@v0.20.10/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/std@0.114.0/node/events.ts:167:20)
    at https://deno.land/x/edgedb@v0.20.10/_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/edgedb@v0.20.10/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/std@0.114.0/node/events.ts:167:20)
    at https://deno.land/x/edgedb@v0.20.10/_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/edgedb@v0.20.10/_src/rawConn.ts:110:20)
    at TLSSocket.emit (https://deno.land/std@0.114.0/node/events.ts:167:20)
    at https://deno.land/x/edgedb@v0.20.10/_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!

@jaclarke
Copy link
Member

jaclarke commented Jul 4, 2022

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)

@Tricked-dev
Copy link

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)

@thorstenweber83
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants