java: add a test for concurrent close - #2435
Conversation
|
This currently crashes the JVM with |
25b3872 to
dd447a7
Compare
|
Debugged:
|
a270121 to
1c248a9
Compare
|
packets come in through I think the while-loop path should go through |
| .batch_next = null, | ||
| .batch_tail = null, | ||
| .batch_size = 0, | ||
| .batch_allowed = false, |
There was a problem hiding this comment.
We could simplify this API by moving these fields to a separate struct (opaque to the client libraries).
Example:
// Exposed to the client.
pub const PacketData = extern struct {
user_data: ?*anyopaque,
operation: u8,
status: Packet.Status,
data_size: u32,
data: ?*anyopaque,
reserved: [42]u8 = [_]u8{0} ** 42, // Internal fields are just opaque.
comptime {
assert(@sizeOf(PacketData) == @sizeOf(Packet));
assert(@alignOf(PacketData) == @alignOf(Packet));
}
};
// Internal implementation.
pub const Packet = extern struct {
user_data: ?*anyopaque,
operation: u8,
status: Status,
data_size: u32,
data: ?*anyopaque,
next: ?*Packet,
batch_next: ?*Packet,
batch_tail: ?*Packet,
batch_size: u32,
batch_allowed: bool,
reserved: [7]u8 = [_]u8{0} ** 7,
comptime {
assert(@sizeOf(Packet) == 64);
assert(@alignOf(Packet) == 8);
}
}1c248a9 to
5d88850
Compare
|
Ok, so I tried follow batiati's suggestion to refactor the API, but then figured out that that's going to be a large change, and that I don't want to mix bug-fix and a refactor in the same PR. I still want to do a refactor, but I want to more carefully survey our entire C ABI layer before that :P So I decided to go with kprotty's suggestion instead, and to make sure that the cancellation path also goes through So I think I still want to merge what we have here now, to fix the bug in the most straightforward way, and then revisit the wider context later! |
Packets are caller allocated, but callers do not initialize all fields of a packet. Instead, initialization is completed by callee, asynchronously, in `request`. But, if the client is cancelled, we don't get to that initialization, and try to follow the batch_next link list using wild pointers.
5d88850 to
fd1c22d
Compare
| .next = null, | ||
| .user_data = packet.user_data, | ||
| .operation = packet.operation, | ||
| .status = .ok, |
There was a problem hiding this comment.
Note when refactoring tb_packet_t:
status is the only field that is both exposed to the client and updated by tb_client. We should change this API so that the status is instead returned alongside results.
No description provided.