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

Writing to sdtin crashes sketch #29

Open
chpio opened this issue May 3, 2022 · 3 comments
Open

Writing to sdtin crashes sketch #29

chpio opened this issue May 3, 2022 · 3 comments

Comments

@chpio
Copy link
Contributor

chpio commented May 3, 2022

Hi,

i need to run code in nodejs. So my idea was to spawn a nodejs process and communicate with it by sending jsonl messages to stdin (you call it sdtin) & getting jsonl messages back from stdout.

But when i attempt to write to stdin it just crashes sketch. No crash reports in console.

const child = spawn(
	path.resolve(process.cwd(), "./Contents/Sketch/external"),
	[],
	{cwd: path.resolve(process.cwd(), "./Contents/Sketch")},
);

// @ts-ignore
const stdin: Writable = child.stdin || child.sdtin;

const buf = Buffer.from(JSON.stringify({type: "getImages"}) + "\n");
console.log("buf", buf);

await new Promise<void>((onOk, onErr) => {
	// crashes here
	stdin.write(buf, (err) => {
		if (err !== null && err !== undefined) {
			onErr(err);
		} else {
			onOk();
		}
	});
});
@mathieudutour
Copy link
Member

happy to accept a PR to fix it (both the typo and the bug)

@chpio
Copy link
Contributor Author

chpio commented May 4, 2022

the typo is not a problem, but how to even debug the crash?

writeData is deprecated, but that shouldn't cause a crash (or is the underlying implementation using the non-deprecated function internally anyway?).

Are there any typescript declarations for the apple javascript types? Couldn't find any so far. (What's the name of that apple js runtime? Asking so that i can search for it)

@chpio
Copy link
Contributor Author

chpio commented May 4, 2022

There is (sometimes) a crash report created in console.

"libdispatch.dylib":["BUG IN CLIENT OF LIBDISPATCH: dispatch_sync called on queue already owned by current thread","Abort Cause 27022302138863365"]

Illegal instruction: 4

edit: i guess the panic is caused by the blocking write op, that would block the current queue, causing a deadlock?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants