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

Printing the result of hxToBytes will hang the runtime #171

Open
kevinresol opened this issue Jul 21, 2020 · 2 comments
Open

Printing the result of hxToBytes will hang the runtime #171

kevinresol opened this issue Jul 21, 2020 · 2 comments

Comments

@kevinresol
Copy link
Contributor

class Main {
	static function main() {
		var buf = js.node.Buffer.from('foo');
		var bytes = buf.hxToBytes();
		trace(bytes);
	}
}

Run the above code with node 12+, it will hang forever.
node 10 or below is fine though.

However, when run with a debugger (vscode), it will crash with the following error.

Waiting for the debugger to disconnect...
internal/util/inspect.js:1249
  throw err;
  ^

SyntaxError: Invalid regular expression: /(.{2})/: Stack overflow
    at String.replace (<anonymous>)
    at Buffer.inspect (buffer.js:814:41)
    at formatValue (internal/util/inspect.js:693:31)
    at formatProperty (internal/util/inspect.js:1558:11)
    at formatRaw (internal/util/inspect.js:933:9)
    at formatValue (internal/util/inspect.js:721:10)
    at inspect (internal/util/inspect.js:264:10)
    at Buffer.inspect (buffer.js:831:14)
    at formatValue (internal/util/inspect.js:693:31)
    at formatProperty (internal/util/inspect.js:1558:11)
Process exited with code 1

It could be fixed by commentting out a line in the gennerated js:

js_node_buffer__$Buffer_Helper.bytesOfBuffer = function(b) {
	var o = Object.create(haxe_io_Bytes.prototype);
	o.length = b.byteLength;
	// o.b = b; <-- commentting this line will fix the hang
	b.bufferValue = b;
	b.hxBytes = o;
	b.bytes = b;
	return o;
};
@kevinresol
Copy link
Contributor Author

This is the minimum js I reduced:

var haxe_io_Bytes = function() { };
var b = require("buffer").Buffer.from('foo');
var o = Object.create(haxe_io_Bytes.prototype);
o.l = b.byteLength;
o.b = b;
b.b = b;
b.o = o;
console.log('',o);

Apparently all the 4 assignments are required to cause the hang.

I wonder why hxToBytes has to generate so many recursive references?

@nadako
Copy link
Member

nadako commented Jul 21, 2020

I wonder why hxToBytes has to generate so many recursive references?

I think this comes from haxe.io.Bytes, but I'm not sure why these references are there either, maybe this could be cleaned up. Probably it has something to do with re-using the underlying bytes somehow.

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