-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack overflow (EXC_BAD_ACCESS) in cURL.swift #14
Comments
I believe this fixes [Issue PerfectlySoft#14](PerfectlySoft#14), but please take a look.
Can you please scratch a script to reproduce this issue? |
It is intermittent, and (based on the code and my experience with it) depends on the length of time the response takes to arrive. I typically see this condition when using a slow/flaky network connection. The code below is roughly where I see it - nothing too special. You can see the recursive code path, in the stack trace, right? That would seem to depend on new bytes coming in fairly rapidly, to avoid exhausting the stack while waiting for new data. If you see the pull request I made, I just queue the recursive call to avoid exhausting the stack. Seems to work on my end. import PerfectCURL
private func broken() {
while (true) {
let obj = CURLRequest("http://api.bart.gov/api/etd.aspx?cmd=etd&orig=ALL&key=MW9S-E7SL-26DU-VV8V&json=y")
obj.options.append(.connectTimeout(10))
obj.options.append(.timeout(10))
obj.perform {}
}
} |
I didn't find anything wrong for the following snippet:
Package.swift:
can you confirm it? It's pretty fast actually, 4 seconds for 100 requests, nothing wrong, all good.
|
Your snippet looks fine, but from your description, your testing conditions are not correct. As I mentioned, this happens on a slow/flaky network. In that condition, one of your 100 requests will take 10+ seconds to complete. Your 100 requests should take several minutes. |
No, still negative. This time I setup a local server like this:
Then every line of the above snippet keeps the same except it was using Then it yielded like this:
That's the expected outcome, still not crashed - cannot reproduce your issue. Sorry about it. |
So, couple comments:
|
(Perhaps also try turning off the 10 second timeout from my example. That should make it easier to recreate the stack overflow. I only added it to my example because that’s how I’m using it.) |
No, still negative. This time I was using a TCP server to simulate
Then the client snippet was complaining
and then
Still expected and not crashed. Can't reproduce your issue. |
Ok. Well I can confirm that, as I mentioned, on a slow network (tethered to a cellphone on 3G) the stack trace in my initial comment will occur, intermittently. And the code in my pull request reliably solves the stack overflow. Is there any issue with that code? Can you see, from code inspection, the possibility for the stack overflow I mentioned in my initial comment? I can. I suppose I can just use my pull request as the source for my project, if you're not interested in accepting the pull request. Let me know. |
Hi, we are definitely interested in your PR, but the point is that many users are using it so it is really necessary to us to understand what happened and what the consequence might be if an extra thread dispatch applied - CPU usage, memory violation, etc., to outstanding the quality of the whole product. Please be patient and allow us to do more tests on it, seriously. Thank you. |
Sorry, perhaps I misunderstood the tone of your messages - it sounded like you were eager to give up on reproducing the problem. I just hit this issue again, same stack trace, same URLs, same slow 3G mobile network. This happens when the latency is about 1000ms - each packet takes ~1s to traverse the network. Is there any way you can simulate that on your end? Simply adding a long single delay before responding will not reproduce the problem. I'm guessing it is after completing the initial handshake and the data is being transferred. Your code above doesn't look like it actually sends any HTTP responses, it just accepts the initial connection. Perhaps you could use something like Charles or the Network Link Conditioner for MacOS to simulate 1s latency? |
Hello, I'm getting a stack overflow that causes an EXC_BAD_ACCESS crash in cURL.swift. See the stack trace below. It seems like the recursive call back to innerComplete at this line should be added to an async queue or something, rather than being directly recursive?
This is on a Mac running Catalina 10.15.1 (19B88). The stack trace below comes from Perfect-CURL version 3.1.0, but I get this on any 3.x or 4.x version that I've tried. This happens typically when waiting for a CURL response from a slow server that takes a little while (~5-10 seconds) to respond.
Any help you can give me would be really appreciated.
...
#10 0x0000000100f945d8 in closure #2 in CURLResponse.innerComplete(:) at Perfect-CURL/Sources/PerfectCURL/CURLResponse.swift:206
#11 0x0000000100f9b3a5 in CURL.ioWait(:) at Perfect-CURL/Sources/PerfectCURL/cURL.swift:222
#12 0x0000000100f942d7 in CURLResponse.innerComplete(:) at Perfect-CURL/Sources/PerfectCURL/CURLResponse.swift:205
#13 0x0000000100f945d8 in closure #2 in CURLResponse.innerComplete(:) at Perfect-CURL/Sources/PerfectCURL/CURLResponse.swift:206
#14 0x0000000100f9b3a5 in CURL.ioWait(:) at Perfect-CURL/Sources/PerfectCURL/cURL.swift:222
...
#1298 0x0000000100f9b3a5 in CURL.ioWait(:) at Perfect-CURL/Sources/PerfectCURL/cURL.swift:222
#1299 0x0000000100f942d7 in CURLResponse.innerComplete(:) at Perfect-CURL/Sources/PerfectCURL/CURLResponse.swift:205
#1300 0x0000000100f945d8 in closure #2 in CURLResponse.innerComplete(:) at Perfect-CURL/Sources/PerfectCURL/CURLResponse.swift:206
#1301 0x0000000100f9bde7 in closure #1 in CURL.ioWait(_:) at Perfect-CURL/Sources/PerfectCURL/cURL.swift:241
The text was updated successfully, but these errors were encountered: