uNetworking / uSockets

Miniscule cross-platform eventing, networking & crypto for async applications
Apache License 2.0
1.29k stars 268 forks source link

[GCD] Crash on macOS after connection refused #62

Closed snej closed 4 years ago

snej commented 5 years ago

On macOS 1014, opening a client connection (with or without SSL) to a port with no listener (i.e. the connection will fail with ECONNREFUSED) results in a crash in gcd.c.

Steps

  1. Compile http_load_test.c
  2. Run http_load_test 1 localhost xxxxx where xxxxx is a port number with nothing listening

The result is basically the same whether or not the constant SSL is defined as 0 or 1.

Result

* thread #2, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x00000001011260ec libdispatch.dylib`_dispatch_lane_resume + 623
  * frame #1: 0x0000000100082dda HelloWorld`us_poll_change(p=0x000060b00000aee0, loop=0x0000608000008820, events=3) at gcd.c:84:9
    frame #2: 0x0000000100096991 HelloWorld`us_socket_write(ssl=0, s=0x000060b00000aee0, data="GET / HTTP/1.0\r\n\r\n", length=1023, msg_more=0) at socket.c:73:9
    frame #3: 0x00000001000010db HelloWorld`on_http_socket_open(s=0x000060b00000aee0, is_client=1, ip=0x0000000000000000, ip_length=0) at http_client_test.c:64:27
    frame #4: 0x00000001000925e7 HelloWorld`us_internal_dispatch_ready_poll(p=0x000060b00000aee0, error=0, events=2) at loop.c:142:17
    frame #5: 0x00000001000819bc HelloWorld`gcd_write_handler(p=0x000060b00000aee0) at gcd.c:48:5
    frame #6: 0x000000010111ef1b libdispatch.dylib`_dispatch_client_callout + 8
    frame #7: 0x00000001011222be libdispatch.dylib`_dispatch_continuation_pop + 563
    frame #8: 0x0000000101136a87 libdispatch.dylib`_dispatch_source_invoke + 2124
    frame #9: 0x0000000101126e76 libdispatch.dylib`_dispatch_lane_serial_drain + 276
    frame #10: 0x0000000101127f4e libdispatch.dylib`_dispatch_lane_invoke + 493
    frame #11: 0x0000000101131824 libdispatch.dylib`_dispatch_root_queue_drain + 334
    frame #12: 0x00000001011322da libdispatch.dylib`_dispatch_worker_thread2 + 125
    frame #13: 0x00000001011980b7 libsystem_pthread.dylib`_pthread_wqthread + 583
    frame #14: 0x0000000101197e01 libsystem_pthread.dylib`start_wqthread + 13

Configuration

uSockets built from tag v0.3.1 macOS 10.14.5 Xcode 11b4

ghost commented 5 years ago

Yep GCD is very incomplete and crashes

snej commented 5 years ago

I wish you had called this out in the README or elsewhere...

snej commented 5 years ago

Any clues as to what's going wrong? I know dispatch queues fairly well but I've never worked with dispatch sources.

ghost commented 5 years ago

https://github.com/uNetworking/uSockets/blob/master/src/eventing/gcd.c#L132

It's incomplete, some parts are left unfinished

snej commented 5 years ago

I'll switch to kqueues then ... are they more stable?

ghost commented 5 years ago

Yes Kqueue is tested and should be working pretty well

ghost commented 4 years ago

Don't have macOS anymore -> closing