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

[windows] IPC #8497

Closed
wants to merge 12 commits into from
Closed

[windows] IPC #8497

wants to merge 12 commits into from

Conversation

cirospaciari
Copy link
Member

What does this PR do?

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

Existing Tests

Copy link
Contributor

github-actions bot commented Jan 26, 2024

Copy link
Contributor

github-actions bot commented Jan 26, 2024

Copy link
Contributor

github-actions bot commented Jan 26, 2024

Copy link
Contributor

github-actions bot commented Jan 26, 2024

Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using libuv methods directly, please add some wrappers to make this code more maintainable

src/bun.js/ipc.zig Outdated Show resolved Hide resolved
log("processSend {d}", .{bytes.len});
if (bytes.len == 0) return;

const req = bun.new(uv.uv_write_t, std.mem.zeroes(uv.uv_write_t));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary? Can we use uv_try_write and be notified when the pipe is writable instead? That would simplify this code and reduce memory allocations.

Copy link
Member Author

@cirospaciari cirospaciari Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did almost that, libuv dont have a way to know when is writable but I did something similiar that we already did on subprocess.

src/bun.js/ipc.zig Outdated Show resolved Hide resolved
}
}

fn uvWriteCallback(req: *uv.uv_write_t, status: uv.ReturnCode) callconv(.C) void {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do use this approach - uv.uv_write, we should have a wrapper so the arguments are this: *NamedIPCPipeData instead of having to deal with the internals of libuv everywhere

Suggested change
fn uvWriteCallback(req: *uv.uv_write_t, status: uv.ReturnCode) callconv(.C) void {
fn onWriteComplete(this: *NamedIPCPipeData, result: union(enum) { written: u32, err: bun.sys.Error}) callconv(.C) void {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont have a reliable internal way to see how many bytes was written only using the libuv struct (to avoid allocations) on windows, so I did fn onWriteComplete(this: *NamedPipeIPCData, status: uv.ReturnCode) void but is already way better

src/bun.js/ipc.zig Outdated Show resolved Hide resolved
src/bun.js/ipc.zig Outdated Show resolved Hide resolved
src/bun.js/javascript.zig Outdated Show resolved Hide resolved
src/bun.js/ipc.zig Outdated Show resolved Hide resolved
src/bun.js/ipc.zig Outdated Show resolved Hide resolved
src/bun.js/ipc.zig Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Jan 26, 2024

❌🪟 @cirospaciari, there are 5 test regressions on Windows x86_64

  • test\bundler\bundler_edgecase.test.ts
  • test\bundler\cli.test.ts
  • test\cli\inspect\inspect.test.ts
  • test\js\third_party\postgres\postgres.test.ts
  • test\js\web\timers\setInterval.test.js

Full Test Output

@cirospaciari
Copy link
Member Author

Instead of using libuv methods directly, please add some wrappers to make this code more maintainable

@Jarred-Sumner Added wrappers, now I'm using try_write, and using uv_write as mechanism to know when we are writable, and fixed the memory issue.

@Jarred-Sumner
Copy link
Collaborator

@cirospaciari there are merge conflicts


const rc = uv_write(req, stream, @ptrCast(&req.write_buffer), 1, &Wrapper.uvWriteCb);
if (rc.errno()) |errno| {
return .{ .err = .{ .errno = errno, .syscall = .write, .from_libuv = true } };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the from_uv's here will cause incorrect error messages

writer.flush();
} else {
// echo
const writer = Bun.stdout.writer();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const writer = Bun.stdout.writer();
for await (let chunk of Bun.stdin) {
console.write(chunk);
}

process.exit(0);
}
case "cat": {
if (fs.existsSync(argument)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (fs.existsSync(argument)) {
await Bun.write(Bun.stdout, Bun.file(argument))

Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spawn test is failing

if (map.map.fetchSwapRemove("BUN_INTERNAL_IPC_FD")) |kv| {
if (std.fmt.parseInt(i32, kv.value.value, 10) catch null) |fd| {
this.initIPCInstance(bun.toFD(fd));
if (map.map.fetchSwapRemove("BUN_INTERNAL_IPC_PIPE")) |kv| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we cant use the same environment variable as it is on posix.

one lookup instead of two?

@cirospaciari
Copy link
Member Author

Closed in favor of #8456

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

Successfully merging this pull request may close these issues.

3 participants