Open irishburlybear opened 4 days ago
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
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);
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);
}
}
};
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.
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);
}
}
I also tried adding await locals.db.close()
at the end of the actions print_label:
Still crashes after about 3 refreshes..
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
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
irishburlybear@gmail.com
Is there an existing issue for this?
Code of Conduct