Skip to content

[bug] v.next is not proper cleared for re-enqueue a completion between different queues #169

Open
@dacheng-gao

Description

@dacheng-gao

https://github.com/mitchellh/libxev/blob/main/src/queue.zig#L24C13-L24C36

/// Enqueue a new element to the back of the queue.
pub fn push(self: *Self, v: *T) void {
    assert(v.next == null);

    if (self.tail) |tail| {
        // If we have elements in the queue, then we add a new tail.
        tail.next = v;
        self.tail = v;
    } else {
        // No elements in the queue we setup the initial state.
        self.head = v;
        self.tail = v;
    }
}

I got error due to the assert while run benchmark for my project, here is the backtrace:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x0000000198051388 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x000000019808a88c libsystem_pthread.dylib`pthread_kill + 296
    frame #2: 0x0000000197f93c60 libsystem_c.dylib`abort + 124
    frame #3: 0x0000000100009dbc tinyproxy_zig`posix.abort at posix.zig:710:29
    frame #4: 0x0000000100005afc tinyproxy_zig`debug.defaultPanic(msg=(ptr = "reached unreachable code", len = 24), first_trace_addr=(data = 4294999376, some = '\x01')) at debug.zig:676:16
    frame #5: 0x000000010000d5b8 tinyproxy_zig`debug.FullPanic((function 'defaultPanic')).reachedUnreachable at debug.zig:63:17
    frame #6: 0x0000000100007d50 tinyproxy_zig`debug.assert(ok=false) at debug.zig:522:14
  * frame #7: 0x00000001000a388c tinyproxy_zig`queue.Intrusive(self=0x00000001002c0028, v=0x000000010480f720).push at queue.zig:24:19
    frame #8: 0x00000001000a1414 tinyproxy_zig`backend.kqueue.Loop.submit(self=0x00000001002c0000) at kqueue.zig:249:38
    frame #9: 0x00000001000a5570 tinyproxy_zig`backend.kqueue.Loop.tick(self=0x00000001002c0000, wait=1) at kqueue.zig:357:24
    frame #10: 0x00000001000a6ecc tinyproxy_zig`backend.kqueue.Loop.run(self=0x00000001002c0000, mode=once) at kqueue.zig:287:35
    frame #11: 0x00000001000a7110 tinyproxy_zig`asyncio.Executor.tick(self=0x0000000100200000) at asyncio.zig:61:26
    frame #12: 0x00000001000a737c tinyproxy_zig`asyncio.runCoro__anon_20532(exec=0x0000000100200000, frame=<unavailable>) at asyncio.zig:93:45
    frame #13: 0x00000001000ad16c tinyproxy_zig`asyncio.run__anon_20251(exec=0x0000000100200000) at asyncio.zig:83:16
    frame #14: 0x00000001000ad4d4 tinyproxy_zig`main.main at main.zig:35:16
    frame #15: 0x00000001000ad988 tinyproxy_zig`start.main [inlined] start.callMain at start.zig:656:37
    frame #16: 0x00000001000ad97c tinyproxy_zig`start.main [inlined] start.callMainWithArgs at start.zig:616:20
    frame #17: 0x00000001000ad904 tinyproxy_zig`start.main(c_argc=1, c_argv=0x000000016fdff610, c_envp=0x000000016fdff620) at start.zig:631:28
    frame #18: 0x0000000197ceab98 dyld`start + 6076
(lldb) frame var
(queue.Intrusive(backend.kqueue.Completion) *) self = 0x00000001002c0028
(backend.kqueue.Completion *) v = 0x000000010480f720
(lldb) print v.next
(backend.kqueue.Completion *) 0x000000010481f720

apparently, v.next is not null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions