mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Lack of progress
This commit is contained in:
@@ -4,7 +4,7 @@ register_repository(
|
||||
REPOSITORY
|
||||
oven-sh/libuv
|
||||
COMMIT
|
||||
537d74411e9a5587bc5c6dd9ca04a77976ecb120
|
||||
271d173b6ebd4dfeb692862df2b03af48dcfb16b
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
|
||||
7
repro-hell/beancounter.ts
Normal file
7
repro-hell/beancounter.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
let count = 0;
|
||||
process.stdin.on("data", chunk => {
|
||||
count += chunk.length;
|
||||
});
|
||||
process.stdin.on("end", () => {
|
||||
console.log(count);
|
||||
});
|
||||
1
repro-hell/reader.ts
Normal file
1
repro-hell/reader.ts
Normal file
@@ -0,0 +1 @@
|
||||
process.stdin.pipe(process.stdout);
|
||||
@@ -1,3 +1,5 @@
|
||||
const mlog = @import("../../../../mlog.zig").log;
|
||||
|
||||
pub fn NewStaticPipeWriter(comptime ProcessType: type) type {
|
||||
return struct {
|
||||
const This = @This();
|
||||
@@ -35,6 +37,7 @@ pub fn NewStaticPipeWriter(comptime ProcessType: type) type {
|
||||
}
|
||||
|
||||
pub fn close(this: *This) void {
|
||||
mlog("StaticPipeWriter(0x{x}) close()\n", .{@intFromPtr(this)});
|
||||
log("StaticPipeWriter(0x{x}) close()", .{@intFromPtr(this)});
|
||||
this.writer.close();
|
||||
}
|
||||
@@ -60,6 +63,7 @@ pub fn NewStaticPipeWriter(comptime ProcessType: type) type {
|
||||
}
|
||||
|
||||
pub fn start(this: *This) bun.sys.Maybe(void) {
|
||||
mlog("StaticPipeWriter(0x{x}) start()\n", .{@intFromPtr(this)});
|
||||
log("StaticPipeWriter(0x{x}) start()", .{@intFromPtr(this)});
|
||||
this.ref();
|
||||
this.buffer = this.source.slice();
|
||||
|
||||
@@ -595,7 +595,10 @@ pub const FD = packed struct(backing_int) {
|
||||
pub const truncate = bun.sys.ftruncate;
|
||||
pub const unlinkat = bun.sys.unlinkat;
|
||||
pub const updateNonblocking = bun.sys.updateNonblocking;
|
||||
pub const write = bun.sys.write;
|
||||
const Error = @import("./sys/Error.zig");
|
||||
pub fn write(fd: bun.FileDescriptor, bytes: []const u8) bun.api.node.Maybe(usize, Error) {
|
||||
return bun.sys.write(fd, bytes);
|
||||
}
|
||||
pub const writeNonblocking = bun.sys.writeNonblocking;
|
||||
pub const writev = bun.sys.writev;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const mlog = @import("../mlog.zig").log;
|
||||
|
||||
// This is a runtime type instead of comptime due to bugs in Zig.
|
||||
// https://github.com/ziglang/zig/issues/18664
|
||||
const BufferedReaderVTable = struct {
|
||||
@@ -923,6 +925,7 @@ pub const WindowsBufferedReader = struct {
|
||||
const nread_int = nread.int();
|
||||
|
||||
bun.sys.syslog("onStreamRead(0x{d}) = {d}", .{ @intFromPtr(this), nread_int });
|
||||
mlog("onStreamRead(0x{d}) = {d}\n", .{ @intFromPtr(this), nread_int });
|
||||
|
||||
// NOTE: pipes/tty need to call stopReading on errors (yeah)
|
||||
switch (nread_int) {
|
||||
|
||||
70
src/mlog.zig
Normal file
70
src/mlog.zig
Normal file
@@ -0,0 +1,70 @@
|
||||
const std = @import("std");
|
||||
const c = @cImport({
|
||||
@cInclude("stdlib.h");
|
||||
});
|
||||
|
||||
const Logger = struct {
|
||||
var log_file: ?std.fs.File = null;
|
||||
var proc_id: std.os.windows.DWORD = 0;
|
||||
var name_buf: [64]u8 = undefined;
|
||||
var name: []u8 = undefined;
|
||||
|
||||
export fn cleanup() void {
|
||||
if (Logger.log_file) |*file| {
|
||||
file.sync() catch {
|
||||
@panic("Failed to flush mlog.txt: {any}\n");
|
||||
};
|
||||
|
||||
file.close();
|
||||
Logger.log_file = null;
|
||||
}
|
||||
}
|
||||
|
||||
fn getAndOpenFile() *std.fs.File {
|
||||
if (Logger.log_file) |*file| {
|
||||
return file;
|
||||
}
|
||||
|
||||
Logger.proc_id = std.os.windows.GetCurrentProcessId();
|
||||
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa.deinit();
|
||||
|
||||
var cwd = std.fs.cwd();
|
||||
|
||||
Logger.name = std.fmt.bufPrint(&name_buf, "mlog_{}.txt", .{Logger.proc_id}) catch {
|
||||
@panic("Failed to format mlog filename: {any}\n");
|
||||
};
|
||||
|
||||
Logger.log_file = cwd.openFile(Logger.name, .{
|
||||
.mode = .read_write,
|
||||
}) catch
|
||||
cwd.createFile(
|
||||
Logger.name,
|
||||
.{
|
||||
.read = true,
|
||||
.truncate = true,
|
||||
},
|
||||
) catch
|
||||
@panic("Failed to create mlog.txt: {any}\n");
|
||||
|
||||
_ = c.atexit(cleanup);
|
||||
|
||||
return &(Logger.log_file orelse unreachable);
|
||||
}
|
||||
|
||||
pub fn log(comptime fmt: []const u8, args: anytype) void {
|
||||
const file = Logger.getAndOpenFile();
|
||||
|
||||
const writer = file.writer();
|
||||
|
||||
const nanos = std.time.nanoTimestamp();
|
||||
std.fmt.format(writer, "[{}] (pid {}) " ++ fmt, .{ nanos, Logger.proc_id } ++ args) catch {
|
||||
@panic("Failed to write to mlog.txt: {any}\n");
|
||||
};
|
||||
|
||||
std.debug.print("Saved output to {s}.\n", .{name_buf});
|
||||
}
|
||||
};
|
||||
|
||||
pub const log = Logger.log;
|
||||
@@ -1,3 +1,4 @@
|
||||
const mlog = @import("../mlog.zig").log;
|
||||
// const IPC = @import("../bun.js/ipc.zig");
|
||||
|
||||
pub const Stdio = util.Stdio;
|
||||
@@ -1135,6 +1136,7 @@ pub const PipeReader = struct {
|
||||
this.process = process;
|
||||
this.event_loop = event_loop;
|
||||
if (Environment.isWindows) {
|
||||
mlog("Starting with current pipe...\n", .{});
|
||||
return this.reader.startWithCurrentPipe();
|
||||
}
|
||||
|
||||
@@ -1158,6 +1160,7 @@ pub const PipeReader = struct {
|
||||
pub const toJS = toReadableStream;
|
||||
|
||||
pub fn onReadChunk(ptr: *anyopaque, chunk: []const u8, has_more: bun.io.ReadState) bool {
|
||||
mlog("Reading a chunk...\n", .{});
|
||||
var this: *PipeReader = @ptrCast(@alignCast(ptr));
|
||||
this.buffered_output.append(chunk);
|
||||
log("PipeReader(0x{x}, {s}) onReadChunk(chunk_len={d}, has_more={s})", .{ @intFromPtr(this), @tagName(this.out_type), chunk.len, @tagName(has_more) });
|
||||
@@ -1179,6 +1182,7 @@ pub const PipeReader = struct {
|
||||
}
|
||||
|
||||
pub fn onReaderDone(this: *PipeReader) void {
|
||||
mlog("The reader is done...\n", .{});
|
||||
log("onReaderDone(0x{x}, {s})", .{ @intFromPtr(this), @tagName(this.out_type) });
|
||||
const owned = this.toOwnedSlice();
|
||||
this.state = .{ .done = owned };
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
//!
|
||||
//! Sometimes this namespace is referred to as "Syscall", prefer "bun.sys"/"sys"
|
||||
|
||||
const mlog = @import("./mlog.zig").log;
|
||||
const This = @This();
|
||||
|
||||
//
|
||||
@@ -1550,6 +1551,7 @@ pub fn write(fd: bun.FileDescriptor, bytes: []const u8) Maybe(usize) {
|
||||
// "WriteFile sets this value to zero before doing any work or error checking."
|
||||
var bytes_written: u32 = undefined;
|
||||
bun.assert(bytes.len > 0);
|
||||
mlog("We're about to WriteFile({}, {})\n", .{ fd, adjusted_len });
|
||||
const rc = kernel32.WriteFile(
|
||||
fd.cast(),
|
||||
bytes.ptr,
|
||||
|
||||
Reference in New Issue
Block a user