treeform / puppy

Puppy fetches via HTTP and HTTPS
MIT License
184 stars 27 forks source link

On mac OS, joinThread hangs after calling puppy.fetch in the thread #48

Closed oakes closed 2 years ago

oakes commented 2 years ago

In one of my projects, i'm creating a thread and making network requests from it using puppy. When i'm done, i send a signal that stops the thread and then i wait for the thread to finish using joinThread. With puppy 1.0.3 this worked, but after updating to 1.4.0 i found that joinThread doesn't return.

Here's a minimal example:

https://gist.github.com/oakes/c12bc0e7ff3e6d256dd7f9e41ca8efa4

With puppy 1.0.3 it prints:

Fetch success!
Stopped client thread

With puppy 1.4.0 it prints:

Fetch success!
objc[17434]: NSConcreteMutableData object 0x7fca4400f9d0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug

I'm on mac OS 10.15.7. I tested on ubuntu 20.04 and it seems to work fine there so this is probably only a mac OS issue.

Also, thank you for this library :D

guzba commented 2 years ago

Hello and thanks for reporting the issue and especially thanks for the minimal example.

Currently I am unable to reproduce this issue. I've tried on my M1 Pro (12.1) which not the same as 10.15 but it is what I've got. I also added it to our GitHub Actions and it passed on Mac: https://github.com/guzba/puppy/runs/4822347092?check_suite_focus=true#step:11:136

I ran it with and without --gc:arc. Do both fail with the same error for you?

A further note, the current Channels in Nim is not recommended and the replacement is https://github.com/nim-lang/threading See https://github.com/nim-lang/Nim/issues/19105#issuecomment-974057788 for context and more info.

oakes commented 2 years ago

With arc enabled i get:

Fetch success!
No stack traceback available
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Without arc it just hangs like i described above. Maybe this only happens on 10.15...i'm too afraid to update macos since other things could break.

nim -v
Nim Compiler Version 1.6.2 [MacOSX: amd64]
Compiled at 2021-12-17
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release
treeform commented 2 years ago

I am at M1 macOS 11.3.1. I get no issue running the test case.

Nim Compiler Version 1.6.2 [MacOSX: amd64]
guzba commented 2 years ago

Another anecdote: I have 10.14.16 on a different Mac and test_issue48.nim passes there with both arc and default GC. (Nim 1.6.2, puppy current #head / 1.5.0)

oakes commented 2 years ago

Actually, that test passes for me too. And when i do nimble develop my own example now runs fine. This must have been fixed after 1.4.0 so i'll close this.