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

Bug: Not working with Bun? #159

Open
2 tasks done
gluax opened this issue Jul 28, 2023 · 13 comments
Open
2 tasks done

Bug: Not working with Bun? #159

gluax opened this issue Jul 28, 2023 · 13 comments
Labels
bug Something isn't working

Comments

@gluax
Copy link

gluax commented Jul 28, 2023

Describe the bug

I'm running the following code with bun(version 0.7.0)

import { Surreal } from 'surrealdb.js';


console.log("foo");
const db = new Surreal('http://127.0.0.1:8000/rpc', {
  // Set the namespace and database for the connection
  ns: 'test',
  db: 'test',

  // Set the authentication details for the connection
  auth: {
      user: 'root',
      pass: 'root',
  },
});

await db.info();
console.log("bar"); //this is never hit

The surrealdb logs are as follows:
image

Steps to reproduce

Install bun.
Install surrealdb
bun add surrealdb.js
surreal start --log trace --user root --pass root memory
copy the minimal example to file
bun run index.ts

Expected behaviour

To be able to connect to the DB from typescript within Bun.

SurrealDB version

1.0.0-beta.9+20230402.5eafebd for linux on x86_6

SurrealDB.js version

^0.8.3

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@gluax gluax added the bug Something isn't working label Jul 28, 2023
@gluax
Copy link
Author

gluax commented Jul 28, 2023

I did attempt this with a try catch block as well, but no ever was ever caught and it would still hang at the info or any other execution method.

@gluax
Copy link
Author

gluax commented Jul 28, 2023

This issue does not affect the ExperimentalSurrealHTTP this functions as normal :)

@kearfy
Copy link
Member

kearfy commented Jul 30, 2023

Hi @gluax, we actually run tests against bun. The only known issue there is that the awaiting the closing of the websocket will run forever, looking into that soon. Will also have a look at this, it should work just fine...

@MurkyTheMurloc
Copy link

I have a similar issue when using Bun, I get 2023-08-22 22:30:08 2023-08-22T20:30:08.902561Z TRACE surrealdb::net: RPC Received: { id: '1259', method: 'ping', params: [] } ](surrealdb::net: WebSocket error: Io(Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }))
and my promise from, the operation waits infinity. However, the same code using node works peferkt.

@Micnubinub
Copy link

Micnubinub commented Aug 23, 2023

Hi @gluax, we actually run tests against bun. The only known issue there is that the awaiting the closing of the websocket will run forever, looking into that soon. Will also have a look at this, it should work just fine...

@kearfy Hey, I'm on Bun 0.7.3, surreal 1.0.0-beta.9+20230820.b350f05 and surrealdb.js 0.8.4 and mine just hangs when connecting. You manage to find a fix?

*still the same on Bun 0.8.0

@jpg-gamepad
Copy link

Bun 1.0 just released and still the same issue.

@jpg-gamepad
Copy link

jpg-gamepad commented Sep 10, 2023

I looked at the source code, and it seems the experimental http version works with Bun run!
There's no documentation on it, but something like this should work.

const { ExperimentalSurrealHTTP } = require('surrealdb.js');
const db = new ExperimentalSurrealHTTP();

async function main() {
	try {
		await db.connect('http://127.0.0.1:8000/rpc', {});
		// Select a specific namespace / database
		await db.use({ns: 'test', db: 'test'});

		// Create a new person with a random id
		let created = await db.create("person", {
			title: 'Founder & CEO',
			name: {
				first: 'Tobie',
				last: 'Morgan Hitchcock',
			},
			marketing: true,
			identifier: Math.random().toString(36).slice(2, 12),
		});

		// Update a person record with a specific id
		let updated = await db.merge("person:jaime", {
			marketing: true,
		});

		// Select all people records
		let people = await db.select("person");

		// Perform a custom advanced query
		let groups = await db.query('SELECT marketing, count() FROM type::table($tb) GROUP BY marketing', {
			tb: 'person',
		});

		console.log(people);
		console.log(groups);

	} catch (e) {
		console.error('ERROR', e);
	}
}

main();

@baadc0de
Copy link

baadc0de commented Sep 10, 2023

For me, the one-shot connect method worked and the above separated signing/use did not.

import {ExperimentalSurrealHTTP} from 'surrealdb.js'

const surreal = new ExperimentalSurrealHTTP()

await surreal.connect('http://localhost:8000/rpc', {auth: {user: 'root', pass: 'root'}, ns: 'test', db: 'test'})

@kearfy
Copy link
Member

kearfy commented Sep 12, 2023

Hey everyone, as per the bun docs, their websocket implementation is still experimental and it does not properly pass all test suites. The broken pipe error is something that the JS side of things does not influence and really rather is an issue in Bun's websocket implementation. I'm afraid I can't make it any better for the moment! Will leave the issue open however

@paperdave
Copy link

This is a bug in Bun, not surrealdb. Our WebSocket client has some issues. We should open a tracking issue in Bun's repo so we don't forget about it though.

@Autumnlight02
Copy link

oven-sh/bun#5434

@LucyEgan
Copy link

LucyEgan commented Dec 5, 2023

This is now working for us in bun 1.0.15 as they have updated their websocket client

@burakakca
Copy link

I tried yesterday and surreal.js it's working but surreal.node gave me error

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

10 participants