don't try (and fail) to get userData after clearing context

This commit is contained in:
Karl Seguin
2025-03-03 19:44:38 +08:00
parent accf2c0e5e
commit 2609671982
2 changed files with 21 additions and 20 deletions

View File

@@ -73,54 +73,55 @@ pub const LightPanda = struct {
);
}
fn handleError(self: *LightPanda, ctx: *Client.Ctx, err: anyerror) anyerror!void {
ctx.deinit();
self.client_context_pool.destroy(ctx);
fn handleError(sending: *Sending, ctx: *Client.Ctx, err: anyerror) anyerror!void {
const lightpanda = sending.lightpanda;
ctx.deinit();
lightpanda.client_context_pool.destroy(ctx);
var sending: *Sending = @ptrCast(@alignCast(ctx.userData));
sending.deinit();
self.sending_pool.destroy(sending);
lightpanda.sending_pool.destroy(sending);
log.info("request failure: {}", .{err});
}
fn onRequestConnect(ctx: *Client.Ctx, res: anyerror!void) anyerror!void {
var sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return sending.lightpanda.handleError(ctx, err);
const sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return handleError(sending, ctx, err);
ctx.req.transfer_encoding = .{ .content_length = sending.body.len };
return ctx.req.async_send(ctx, onRequestSend) catch |err| {
return sending.lightpanda.handleError(ctx, err);
return handleError(sending, ctx, err);
};
}
fn onRequestSend(ctx: *Client.Ctx, res: anyerror!void) anyerror!void {
var sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return sending.lightpanda.handleError(ctx, err);
const sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return handleError(sending, ctx, err);
return ctx.req.async_writeAll(sending.body, ctx, onRequestWrite) catch |err| {
return sending.lightpanda.handleError(ctx, err);
return handleError(sending, ctx, err);
};
}
fn onRequestWrite(ctx: *Client.Ctx, res: anyerror!void) anyerror!void {
var sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return sending.lightpanda.handleError(ctx, err);
const sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return handleError(sending, ctx, err);
return ctx.req.async_finish(ctx, onRequestFinish) catch |err| {
return sending.lightpanda.handleError(ctx, err);
return handleError(sending, ctx, err);
};
}
fn onRequestFinish(ctx: *Client.Ctx, res: anyerror!void) anyerror!void {
var sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return sending.lightpanda.handleError(ctx, err);
const sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return handleError(sending, ctx, err);
return ctx.req.async_wait(ctx, onRequestWait) catch |err| {
return sending.lightpanda.handleError(ctx, err);
return handleError(sending, ctx, err);
};
}
fn onRequestWait(ctx: *Client.Ctx, res: anyerror!void) anyerror!void {
var sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return sending.lightpanda.handleError(ctx, err);
const sending: *Sending = @ptrCast(@alignCast(ctx.userData));
res catch |err| return handleError(sending, ctx, err);
const lightpanda = sending.lightpanda;

View File

@@ -10,7 +10,7 @@ const log = std.log.scoped(.telemetry);
const ID_FILE = "lightpanda.id";
pub const Telemetry = TelemetryT(blk: {
if (builtin.mode == .Debug or builtin.is_test) break :blk NoopProvider;
// if (builtin.mode == .Debug or builtin.is_test) break :blk NoopProvider;
break :blk @import("lightpanda.zig").LightPanda;
});