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: EngineDisconnet if I access the database too fast... #293

Open
2 tasks done
irishburlybear opened this issue Jul 1, 2024 · 9 comments
Open
2 tasks done

Bug: EngineDisconnet if I access the database too fast... #293

irishburlybear opened this issue Jul 1, 2024 · 9 comments
Labels
noissue question Further information is requested

Comments

@irishburlybear
Copy link

Describe the bug

I get this error if there are too many queries happening I guess. (svelte) I have a hooks accessing the info for the user.

EngineDisconnected: The engine reported the connection to SurrealDB has dropped
at file:///home/gray/programs/timeclock/node_modules/surrealdb.js/esm/surreal.js:116:50
at Array.map ()
at Surreal.clean (file:///home/gray/programs/timeclock/node_modules/surrealdb.js/esm/surreal.js:116:17)
at Surreal.close (file:///home/gray/programs/timeclock/node_modules/surrealdb.js/esm/surreal.js:108:14)
at Surreal.connect (file:///home/gray/programs/timeclock/node_modules/surrealdb.js/esm/surreal.js:73:20)
at Object.handle (/home/gray/programs/timeclock/src/hooks.server.js:57:11)
at Module.respond (/home/gray/programs/timeclock/node_modules/@sveltejs/kit/src/runtime/server/respond.js:319:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///home/gray/programs/timeclock/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:524:22

Steps to reproduce

In sveltekit, have hooks.server.js get the current user info, then do a db query immediately after.

Expected behaviour

Not to be disconnected from the engine...

SurrealDB version

1.5.3

SurrealDB.js version

beta.9

Contact Details

[email protected]

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
@irishburlybear irishburlybear added the bug Something isn't working label Jul 1, 2024
@kearfy
Copy link
Member

kearfy commented Jul 1, 2024

Hey @irishburlybear, this error is sent to all pending requests if you close the connection before they can be completed. Are you sure that you await the info call? It would help out a lot if you could send over a reproducable example

@kearfy kearfy added question Further information is requested noissue and removed bug Something isn't working labels Jul 1, 2024
@irishburlybear
Copy link
Author

irishburlybear commented Jul 1, 2024

hooks.server.js: Notice I am using ws because http didn't work / doesn't work..

await db.connect('ws://127.0.0.1:8000/rpc')
	await db.authenticate(session)

	event.locals.user = await db.info()
	event.locals.db = db

	return await resolve(event);

@irishburlybear
Copy link
Author

irishburlybear commented Jul 1, 2024

It will run once, but if I refresh to generate another pdf, I get the above error...

import { printRegularLabel } from '$lib/reports';
import { RecordId } from 'surrealdb.js';

export const actions = {
	print_label: async ({ request, locals, params }) => {
		const data = Object.fromEntries(await request.formData());
		console.log(params, data);

		try {
			if (data.print_type === 'reg') {
				const employee = await locals.db.select(new RecordId('employees', params.id));

				console.log('print employee:', employee);

				return await printRegularLabel(employee);
			}
		} catch (err) {
			console.log(err.message);
		}
	}
};

@irishburlybear
Copy link
Author

irishburlybear commented Jul 1, 2024

BTW, I'm using a query because I couldn't use select. But maybe because RecordID, I'm doing it wrong?

Update! I rewrote select to use the RecordID. Still has the same issue.

@irishburlybear
Copy link
Author

Here is the function printRegualLabel():

import PdfPrinter from 'pdfmake';

import { v4 as uuid } from 'uuid';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';

export async function printRegularLabel(employee) {

    const fonts = {
        Roboto: {
          normal: 'src/lib/fonts/roboto/Roboto-Regular.ttf',
          bold: 'src/lib/fonts/roboto/Roboto-Bold.ttf'
        }
      }

    const dd = new PdfPrinter(fonts)

	let pdf = {
		pageSize: 'A4',
		pageOrientation: 'portrait',
		pageMargins: [40, 60, 40, 20],
        content: [
            {text: employee.first+' '+employee.last, fontSize: 12, margin: [0,2] },
            {qr: employee.ulid, fit: '100', eccLevel: 'H'}
        ]
	};

	let filename = uuid();
	const dir = path.join(os.tmpdir(), `${filename}.pdf`);

	try {
		let pdfDoc = dd.createPdfKitDocument(pdf);
		pdfDoc.pipe(fs.createWriteStream(dir));
		pdfDoc.end();

		return filename;
	} catch (err) {
		console.log(err);
	}
}

@irishburlybear
Copy link
Author

I also tried adding await locals.db.close() at the end of the actions print_label:
Still crashes after about 3 refreshes..

@irishburlybear
Copy link
Author

irishburlybear commented Jul 1, 2024

Here is the new output after switching to http protocol:

Getting PDF is the filename I create in the tmp/os folder for it to be downloaded
The data here is all dummy data...

Getting pdf... 716625ec-c30e-44bc-9d96-acd3e3a49abc
{ id: 'yf5524ihygkf9s0t6ge9' } { print_type: 'reg' }
print employee: {
active: true,
first: 'Jesse',
id: RecordId { tb: 'employees', id: 'yf5524ihygkf9s0t6ge9' },
last: 'Cruncher',
simple_id: 6795,
ulid: '01J0HMNPDYFW3WZ7PADJ3M0WXJ'
}
Search: null
Getting pdf... 2da0be34-1bca-4980-942b-b0387cad2fbd
{ id: 'yf5524ihygkf9s0t6ge9' } { print_type: 'reg' }
print employee: {
active: true,
first: 'Jesse',
id: RecordId { tb: 'employees', id: 'yf5524ihygkf9s0t6ge9' },
last: 'Cruncher',
simple_id: 6795,
ulid: '01J0HMNPDYFW3WZ7PADJ3M0WXJ'
}
ConnectionUnavailable: There is no connection available at this moment.
at HttpEngine.rpc (file:///home/gray/programs/timeclock/node_modules/surrealdb.js/esm/library/engine.js:223:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Surreal.info (file:///home/gray/programs/timeclock/node_modules/surrealdb.js/esm/surreal.js:168:21)
at async Object.handle (/home/gray/programs/timeclock/src/hooks.server.js:66:22)
at async Module.respond (/home/gray/programs/timeclock/node_modules/@sveltejs/kit/src/runtime/server/respond.js:319:20)
at async file:///home/gray/programs/timeclock/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:524:22
Getting pdf... 8f709fb3-3b0d-4e40-8429-6df0fbe97ddc

@Arhimondus
Copy link

Have the same issue. After a few time the connection has dropped.

@kearfy
Copy link
Member

kearfy commented Jul 12, 2024

Thanks, it's on my list. I'll be looking into this soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
noissue question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants