oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.37k stars 2.78k forks source link

Support for neo4j-driver #9914

Open gramliu opened 7 months ago

gramliu commented 7 months ago

What version of Bun is running?

1.1.0+5903a6141

What platform is your computer?

Darwin 23.3.0 arm64 arm

What steps can reproduce the bug?

I'm using neo4j-driver (5.18.0) to interact with my neo4j graph db. However, I'm encountering issues with running it via bun whereas it's working fine with nodejs.

I have the following minimal script below which creates and returns a new vertex:

import neo4j from "neo4j-driver";

const env = process.env;

async function main () {
  const driver = neo4j.driver(
    env["NEO4J_URL"]!,
    neo4j.auth.basic(env["NEO4J_USERNAME"]!, env["NEO4J_PASSWORD"]!)
  );

  const session = driver.session({
    defaultAccessMode: neo4j.session.WRITE,
  });
  const query = `CREATE (v:VERTEX {id: 'v_123', label: 'dummy'})
  RETURN v;`
  try {
    debugger;
    console.log("Starting session");
    const result = await session.executeWrite(async (txc) => {
      debugger;
      console.log("Running query");
      return txc.run(query);
    });
    console.log(result);
  } finally {
    await session.close();
  }
}

void main();

What is the expected behavior?

Output when running with tsx:

Starting session
Running query
{
  records: [
    Record {
      keys: [Array],
      length: 1,
      _fields: [Array],
      _fieldLookup: [Object]
    }
  ],
  summary: ResultSummary {
    query: {
      text: "CREATE (v:VERTEX {id: 'v_123', label: 'dummy'})\n  RETURN v;",
      parameters: {}
    },
    queryType: 'rw',
    counters: QueryStatistics {
      _stats: [Object],
      _systemUpdates: 0,
      _containsUpdates: true
    },
    updateStatistics: QueryStatistics {
      _stats: [Object],
      _systemUpdates: 0,
      _containsUpdates: true
    },
    plan: false,
    profile: false,
    notifications: [],
    server: ServerInfo {
      address: '<NEO4J_URL>',
      agent: 'Neo4j/5.18-aura',
      protocolVersion: 5.4
    },
    resultConsumedAfter: Integer { low: 3, high: 0 },
    resultAvailableAfter: Integer { low: 44, high: 0 },
    database: { name: 'neo4j' }
  }
}

What do you see instead?

Starting session
^C

Additional information

I tried running with the debugger (--inspect-wait), hence the debugger statements in the code snippet. However, after the first breakpoint, execution just stalls indefinitely. Neither the "Running query", the second breakpoint, nor the console.log after the write ever seem to run.

When I tried stepping through with the debugger, it just seems to lose its handle at some point, so I'm not sure what to look for.

github-actions[bot] commented 3 months ago

This issue is stale and may be closed due to inactivity. If you're still running into this, please leave a comment.

inc16sec commented 3 months ago

Running into the same issue. I was thinking of migrating from Nodejs to Bun for my Neo4j server but this seems to be a no-go for me too.

nicholasoxford commented 3 months ago

Added some more color here:

https://github.com/oven-sh/bun/issues/12772#issuecomment-2283066870

HuakunShen commented 3 months ago

Same problem here. With bun 1.1.25 I could get graphql server working with a local-hosted neo4j DB, but not with a remote DB. Not sure what happens, the connection to Neo4J aura always timeout with 60s when bun is used, but running with node.js works.

nicholasoxford commented 2 months ago

Considering we can't even get an acknowledgement from the Bun team, I had to find a work around. I've raised this issue in Discord and twitter multiple times.

For those running into these issues, you can use the HTTP Query API to perform writes.

To use this locally you need to use the neo4j:5.22.0-enterprise image. To get that to work with docker, you need to pass in a few env variables

 - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
 - NEO4J_server_http__enabled__modules=TRANSACTIONAL_ENDPOINTS,UNMANAGED_EXTENSIONS,BROWSER,ENTERPRISE_MANAGEMENT_ENDPOINTS,QUERY_API_ENDPOINTS

if you previously ran the neo4j docker image locally, you need to check the ports and clear any related volumes

docker-compose down --remove-orphans
lsof -ti :7474 | xargs kill -9
docker volume rm protocol-internal_neo4j_data

Even though neo4j says its not supported in Aura, it currently is.

Electroid commented 2 months ago

Sorry you're running into this, obviously this is a bug a Bun and we need to fix it.

nicholasoxford commented 2 months ago

Hey @Electroid ! Thank you so much for your help

I added you to a private repository which is a fork of the neo4j-driver

I believe you just need to npm install and npm run build in the root. Then run bun mvp-test.mjs. It has the console logs to show you where the hangup is. This repo also has connection strings to a paid neo4j instance. Seriously down to help in any way and I really appreciate you!

whamsicore commented 2 months ago

I have the same issue. I'm forced to use local neo4j desktop

emilianomonzaia commented 1 month ago

For the love of god: we're entering the RAG with Knowledge Graph era and this issue was not prioritized yet?

nicholasoxford commented 2 weeks ago

We had to switch back to Node because this was never addressed @Jarred-Sumner

LUK3D commented 1 week ago

@Jarred-Sumner Please we need some fix or a work around. This is blocking our neo4j server. I was porting my Nodejs server to bun and now I'm blocked by this issue.

inc16sec commented 6 days ago

I'm also still waiting for a fix. @Jarred-Sumner any idea what's going on here?

LUK3D commented 4 days ago

@Electroid Please, can we have an update on this? At least something to know if it will be fixed in the next days or months because my project depends on this.