mtxr / vscode-sqltools

Database management for VSCode
https://vscode-sqltools.mteixeira.dev?utm_source=github&utm_medium=homepage-link
MIT License
1.51k stars 303 forks source link

Endless loop connecting to DuckDB database #1362

Closed evx73 closed 3 months ago

evx73 commented 3 months ago

Describe the bug

Cannot connect to DuckDB database due to broken driver detection behind corporate Proxy.

To Reproduce

0) Set a new DuckDB connection, and connect

1) SqlTools log:

ERROR (ls): Connecting error: {"code":1000,"data":{"notification":"Core/missingModule","dontNotify":true,"args":{"conn":{"name":"DuckDB2","accessMode":"Read/Write","previewLimit":50,"driver":"DuckDB","databaseFilePath":":memory:","isActive":false,"isConnected":false,"id":"DuckDB2|DuckDB||"},"action":"install","deps":[{"type":"package","name":"duckdb-async","version":"0.10.2"}]}}} ns: "conn-manager"

2) Warning: You need to install "duck-async@0.10.2" to conttect to DuckDB

3) Action: Install now

4) Info: "duck-async@0.10.2" installed. Go ahead and connect!

5) Action: Connect to DuckDB

6) Repeat from step "2" above

Expected behavior

Connection to DuckDB after first installation of driver..

Screenshots

Desktop (please complete the following information):

Windows 10 VSCode 1.92.0 Node.js 20.16.0 (LTS) SQLTools 0.28.3 DuckDBDriver for SQLTools

Additional context

Similar to https://github.com/mtxr/vscode-sqltools/issues/318

gjsjohnmurray commented 3 months ago

Please report this to the author of the DUCKDB driver extension.

evx73 commented 3 months ago

I have the same issue with an alternative driver "DuckDB Sql Tools v1.6.0" by "Random Fractals Inc.". Are you sure this is associated with "DuckDBDriver for SQLTools Version 1.0.0" and not SqlTools?

gjsjohnmurray commented 3 months ago

It's possible that both drivers use a post-install download technique that is being blocked by your corporate proxy.

evx73 commented 3 months ago

The dependency was successfully downloaded by npm after configuring npm network access via the proxy. However, the connection manager fails with this error:

[1722959915519] INFO  (ls): Connection instance created for duckdb.
    ns: "conn-manager"
[1722959915532] ERROR (ls): Connecting error: {"code":1000,"data":{"notification":"Core/missingModule","dontNotify":true,"args":{"conn":{"previewLimit":50,"driver":"DuckDB","name":"duckdb","database":":memory:","isActive":false,"isConnected":false,"id":"duckdb|DuckDB||:memory:"},"action":"install","deps":[{"type":"package","name":"duckdb-async","version":"0.10.2"}]}}}
    ns: "conn-manager"
evx73 commented 3 months ago

I have logged the exception that causes the connection to fail. Ideally, connect exceptions should be logged, right?

 exception duckdb-async 0.10.2 Error: Module did not self-register: '\\?\C:\Users\XXXX\AppData\Local\vscode-sqltools\Data\node_modules\duckdb\lib\binding\duckdb.node'.

Do you have any suggestions on how to fix this? I have tried with several versions on nodejs and installed the module several times with no success.

gjsjohnmurray commented 3 months ago

Please do raise this with the extension authors as they are best placed to do the initial investigation, and to raise an issue here if they think something got broken inside the SQLTools core extension.

evx73 commented 3 months ago

The problem seems to be related to the folder permissions of the vscode-sqltools folder, %LOCALAPPDATA%\vscode-sqltools\Data on my Windows installation.

I created a simple app.js script to verify the correct installation of the duckdb-async module.

If I run node app.js under %LOCALAPPDATA%\vscode-sqltools\Data, I get:

Error: Module did not self-register: '\\?\C:\Users\XXXX\AppData\Local\vscode-sqltools\Data\node_modules\duckdb\lib\binding\duckdb.node'.
    at Module._extensions..node (node:internal/modules/cjs/loader:1454:18)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (C:\Users\XXXX\AppData\Local\vscode-sqltools\Data\node_modules\duckdb\lib\duckdb-binding.js:4:15)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12) {
  code: 'ERR_DLOPEN_FAILED'
}

If I copy %LOCALAPPDATA%\vscode-sqltools\ to C:\dev\vscode-sqltools folder and I run node app.js there, the script runs OK.

As a workaround, I created a directory symbolic link from %LOCALAPPDATA%\vscode-sqltools\ to c:\dev\vscode-sqltools . Now SqlTools works OK:

cd
mklink /D vscode-sqltools c:\dev\vscode-sqltools

I hope this will help others as I suspect this will not be fixed...

The app.js script:

var duckdb = require('duckdb-async');

console.log(duckdb.Database);

async function simpleTest() {
  const db = await duckdb.Database.create(":memory:");

  const rows = await db.all("select * from range(1,10)");
  console.log(rows);
}

simpleTest();