You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
create one multi-handle
repeat 20x {
- add 100 http/2 requests to the multi-handle
- run multi handle until all requests are done
- remove requests from the multi-handle
}
The program works on my macos with native libcurl (curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0)
However on Debian (buster) the program segfaults after a while, both when compiled with libcurl4-openssl-dev as well as libcurl4-gnutls-dev. Both versions are libcurl 7.60.0.
I can also reproduce the problem on MacOS if I build libcurl with nghttp2 support:
brew install curl --with-nghttp2
brew link --force curl
I tried rebuilding against the master branch. That fixes the example but my R program still crashes. I haven't been able to translate it to a C example yet but here is the backtrace:
Try this additional patch, which really is a follow-up to that commit I mentioned above:
diff --git a/lib/url.c b/lib/url.c
index 0cab0a303..f1a6e8db4 100644
--- a/lib/url.c+++ b/lib/url.c@@ -1463,10 +1463,11 @@ ConnectionExists(struct Curl_easy *data,
}
if(chosen) {
/* mark it as used before releasing the lock */
chosen->inuse = TRUE;
+ chosen->data = data; /* own it! */
Curl_conncache_unlock(needle);
*usethis = chosen;
return TRUE; /* yes, we found one to use! */
}
Curl_conncache_unlock(needle);
Everything looks good on MacOS now. The crashes were more frequent on Debian, but I don't have time to build a version of libcurl with nghttp2 from source on Linux. Perhaps once this fix is in master I can ask the Debian maintainer of libcurl to give it a try.
I think that is a byte offset, not a line number. Itried building libcurl with --enable-debug --enable-curldebug --disable-hidden-symbols but I'm not getting a better back trace. Here is some output other debug output at least:
I can reproduce (using multi-stress.cpp, Linux) using 7.60. Failures I'm seeing appear similar to the ones discussed in #2669 and recently fixed on master branch.
When building against curl 7.60 + first fix on that PR => can't seem to reproduce
When building against curl 'master' => can't seem to reproduce
Testing using address-sanitizer and debug configure flags.
If you're able to reproduce on Linux using patched curl (or latest git), please let me know --and any suggestions of things to "encourage" seeing this bug would help reproduce--which is important for ability to produce a fix.
@bagder yes that's really cool to hear.
Do you eventually have these fixes on a branch I can use for testing as well? Maybe the #2688 is then solved too.
I'm from the same company as ThomasObenaus, and helped debugging the crash too.
The crash resulted in accessing a former valid, but now invalid (deleted) Curl_easy handle. After a timeout thomas did a curl_multi_remove_handle and a curl_easy_cleanup.
Sometimes the curl_multi_remove_handle did not reset the stream_userdata to zero for this stream id.
When curl wants to close the session, or just find a frame with this now invalid stream id in the session, albeit handling a another Curl_easy handle, it called a callback with a invalid Curl_easy handle -> BOOM,
My fast workaround is, track the session and stream_id in Curl_easy and clear the stream_userdata it when removing the handle in curl_multi_remove_handle. Its just a bell wire around the engine block, but it seems to work for a now. But i prefer a proper bugfix too :-).
@ReneReusner I already landed a few fixes and there are more coming. Once I've landed these fixes I will be very interested in further debugging and testing to make sure we iron out all the last wrinkles.
Let me remind you that I can't reproduce your problem. With @jeroen's example I managed to find and fix a whole slew of issues, but as they've gradually been fixed that sample program now works really well. I'm not entirely convinced it runs 100% fine all the time yet, but without a way to reproduce your case @ThomasObenaus, we risk having to live with that until someone can reproduce it.
@bagder I totally understand this. But yet I found no other way to reproduce than the one I described (which is not transferable to you).
Maybe one last question:
In the logs I see that, when cleaning up the easy_handle, it fails on removing itself from the stream (the call to nghttp2_session_set_stream_user_data fails). And then later when another stream is closed which still contains a reference to that easy_handle it crashes.
I have the feeling that there is sometimes a situation where the easy_handle and the h2-session does not match or get mixed.
Could that be the case? Or can you maybe point me at a location which I should look at for this potential problem? I'm a bit lost in the curl-code since its new for me.
I managed to get some hours at work to look in this problem again. What i had found: On a curl time out in multi.c (~1400)
timeout_ms=Curl_timeleft(data, &now,
(data->mstate <= CURLM_STATE_WAITDO)?
TRUE:FALSE);
if(timeout_ms<0) {
/* Handle timed out */
............
/* Force connection closed if the connection has indeed been used */if(data->mstate>CURLM_STATE_DO) {
streamclose(data->easy_conn, "Disconnected with pending data");
stream_error= TRUE;
}
result=CURLE_OPERATION_TIMEDOUT;
(void)multi_done(&data->easy_conn, result, TRUE);
/* Skip the statemachine and go directly to error handling section. */
goto statemachine_end;
The multi_done here
staticCURLcodemulti_done(structconnectdata**connp,
CURLcodestatus, /* an error if this is called after an error was detected */boolpremature)
needs to clear the user data in the associated stream. If it don't to it, then sometimes when nghttp2 iterate over all stream in a session, sometimes it will find a "stale" user_data and may call a callback with a deleted Curl_easy -> BOOM.
staticCURLMcodemulti_runsingle(structCurl_multi*multi,
structtimevalnow,
structCurl_easy*data)
...
data->state.pipe_broke= FALSE;
data->easy_conn=NULL;
/* My comment for a debug assertion clear http2 session infos, the http2 session is already gone, but the assert in http2.c:1979 assert(!(conn->data->tmp1) || (conn->data->tmp1 == h2)); & co can still bite us, if we get a new connection to continue */
On a broken pipe, Cause i'm not familiar with curl, i don't know if the associated connection can be still used? If yes (maybe its placed in the connection cache), we need to remove the stream_userdata here too.
One another thing. Its not a error but can break on 64bit machines a backtrace in gdb:
sendf.c ~ line 865:
For example on a stale Curl_easy, set.fdebug points to a invalid address, when the cpu jump to it, it crashes yes. BUT (cause of some brain damaged ABI designers, redzone, framepointer optional) the gdb needs a "valid" PC to get the unwind information. If its not in a known region -> no backtrace. Then you need a walk_stack macro. Callbacks for debugging on 64bit machines are not always a good idea.
A callback which point to a invalid address (for example from a old stale Curl_easy) can result in a broken backtrace.
Activity
jeroen commentedon Jun 21, 2018
Here is a backtrace from the above program on macos:
Also sometimes it crashes here:
bagder commentedon Jun 21, 2018
This commit might be the fix you want: 2c15693. It fixed basically the same symptoms.
jeroen commentedon Jun 21, 2018
I tried rebuilding against the master branch. That fixes the example but my R program still crashes. I haven't been able to translate it to a C example yet but here is the backtrace:
bagder commentedon Jun 21, 2018
Try this additional patch, which really is a follow-up to that commit I mentioned above:
jeroen commentedon Jun 21, 2018
Yes this seems to resolve my immediate crash, so that is an improvement :-) I would need to investigate if this also resolves my other issues.
bagder commentedon Jun 21, 2018
Great! I'll hold off merging this for a while to see if you find something else as well...
ConnectionExists: make sure conn->data is set when "taking" a connection
jeroen commentedon Jun 21, 2018
Everything looks good on MacOS now. The crashes were more frequent on Debian, but I don't have time to build a version of libcurl with nghttp2 from source on Linux. Perhaps once this fix is in master I can ask the Debian maintainer of libcurl to give it a try.
jeroen commentedon Jun 22, 2018
I'm still getting an occosional crash. Might be another problem. Here is a backtrace:
bagder commentedon Jun 22, 2018
so which pointer is NULL there? http.c:1862 doesn't seem to be the same line in my code...
ConnectionExists: make sure conn->data is set when "taking" a connection
jeroen commentedon Jun 22, 2018
I think that is a byte offset, not a line number. Itried building libcurl with
--enable-debug --enable-curldebug --disable-hidden-symbolsbut I'm not getting a better back trace. Here is some output other debug output at least:dtzWill commentedon Jun 22, 2018
I can reproduce (using multi-stress.cpp, Linux) using 7.60. Failures I'm seeing appear similar to the ones discussed in #2669 and recently fixed on master branch.
When building against curl 7.60 + first fix on that PR => can't seem to reproduce
When building against curl 'master' => can't seem to reproduce
Testing using address-sanitizer and debug configure flags.
If you're able to reproduce on Linux using patched curl (or latest git), please let me know --and any suggestions of things to "encourage" seeing this bug would help reproduce--which is important for ability to produce a fix.
21 remaining items
ThomasObenaus commentedon Jul 15, 2018
@bagder yes that's really cool to hear.
Do you eventually have these fixes on a branch I can use for testing as well? Maybe the #2688 is then solved too.
bagder commentedon Jul 16, 2018
They will be merged into master. I'll let you know when it's time! (I've been out and about a bit the past few days)
ReneReusner commentedon Jul 16, 2018
Hello
I'm from the same company as ThomasObenaus, and helped debugging the crash too.
The crash resulted in accessing a former valid, but now invalid (deleted) Curl_easy handle. After a timeout thomas did a curl_multi_remove_handle and a curl_easy_cleanup.
Sometimes the curl_multi_remove_handle did not reset the stream_userdata to zero for this stream id.
When curl wants to close the session, or just find a frame with this now invalid stream id in the session, albeit handling a another Curl_easy handle, it called a callback with a invalid Curl_easy handle -> BOOM,
My fast workaround is, track the session and stream_id in Curl_easy and clear the stream_userdata it when removing the handle in curl_multi_remove_handle. Its just a bell wire around the engine block, but it seems to work for a now. But i prefer a proper bugfix too :-).
bagder commentedon Jul 16, 2018
@ReneReusner I already landed a few fixes and there are more coming. Once I've landed these fixes I will be very interested in further debugging and testing to make sure we iron out all the last wrinkles.
bagder commentedon Jul 20, 2018
I just landed #2751 as commit 7b9bc96 and now the crashes are if not gone, at least much less likely to occur.
jeroen commentedon Jul 22, 2018
Thanks, looking good. Are you still planning on a patch release soon?
ThomasObenaus commentedon Jul 25, 2018
Sadly it does not solve #2688. I got the same bt even with the fixes of 7b9bc96.
jeroen commentedon Jul 25, 2018
@ThomasObenaus Did you try 81377ca ?
ThomasObenaus commentedon Jul 25, 2018
@jeroen I tried with current master including 81377ca ,sadly no success :-(
bagder commentedon Jul 25, 2018
Let me remind you that I can't reproduce your problem. With @jeroen's example I managed to find and fix a whole slew of issues, but as they've gradually been fixed that sample program now works really well. I'm not entirely convinced it runs 100% fine all the time yet, but without a way to reproduce your case @ThomasObenaus, we risk having to live with that until someone can reproduce it.
ThomasObenaus commentedon Jul 26, 2018
@bagder I totally understand this. But yet I found no other way to reproduce than the one I described (which is not transferable to you).
Maybe one last question:
In the logs I see that, when cleaning up the easy_handle, it fails on removing itself from the stream (the call to
nghttp2_session_set_stream_user_datafails). And then later when another stream is closed which still contains a reference to that easy_handle it crashes.I have the feeling that there is sometimes a situation where the easy_handle and the h2-session does not match or get mixed.
Could that be the case? Or can you maybe point me at a location which I should look at for this potential problem? I'm a bit lost in the curl-code since its new for me.
bagder commentedon Jul 28, 2018
Okay while #2688 is still happening, @jeroen has confirmed his problems are not showing up anymore so I consider this particular issue fixed.
ReneReusner commentedon Aug 11, 2018
Hello.
I managed to get some hours at work to look in this problem again. What i had found: On a curl time out in multi.c (~1400)
The multi_done here
needs to clear the user data in the associated stream. If it don't to it, then sometimes when nghttp2 iterate over all stream in a session, sometimes it will find a "stale" user_data and may call a callback with a deleted Curl_easy -> BOOM.
I added it in
Please also take a look in multi.c ~ 1350
On a broken pipe, Cause i'm not familiar with curl, i don't know if the associated connection can be still used? If yes (maybe its placed in the connection cache), we need to remove the stream_userdata here too.
One another thing. Its not a error but can break on 64bit machines a backtrace in gdb:
sendf.c ~ line 865:
For example on a stale Curl_easy, set.fdebug points to a invalid address, when the cpu jump to it, it crashes yes. BUT (cause of some brain damaged ABI designers, redzone, framepointer optional) the gdb needs a "valid" PC to get the unwind information. If its not in a known region -> no backtrace. Then you need a walk_stack macro. Callbacks for debugging on 64bit machines are not always a good idea.
A callback which point to a invalid address (for example from a old stale Curl_easy) can result in a broken backtrace.