Opened 11 years ago

Closed 2 weeks ago

#10720 closed defect (fixed)

wxHTTP Read crash in secondary thread on wxGTK

Reported by: bakcsi Owned by:
Priority: normal Milestone:
Component: network Version: stable-latest
Keywords: wxHTTP wxGTK thread Cc: mail@…
Blocked By: Blocking:
Patch: no

Description

The attached program reads from a http stream in a secondary thread.
It usually (but not always) crashes on GTK after a few seconds, mostly (but not always) like it can be seen in the attached stack trace. The same program seems to run stable on MSW. Also, it never crashed on GTK if we put a Sleep(0) in the read thread. (However, we'd like to avoid this Sleep. Also, we don't know if this workaround really solves the problem, or just makes it less frequent.)

We also discovered, that on GTK, in src/common/socket.cpp, line 1283, which looks like this:

if ( rc == 1
wxFD_ISSET(m_fd, &exceptfds) )

sometimes m_fd is an invalid socket, which also results in a crash. So in our tests, we modified this line:

if ( m_fd == INVALID_SOCKET
rc == 1 wxFD_ISSET(m_fd, &exceptfds) )

Also, this other problem never occurred on MSW.

Some details:
WX SVN revision 60255 (and also with earlier 2.9 revisions)
Linux dual 2.6.29.1 #2 SMP Tue Apr 7 18:26:31 CEST 2009 i686 GNU/Linux

Best Regards,
Zsolt

Attachments (3)

test.cpp download (1.4 KB) - added by bakcsi 11 years ago.
Makefile download (706 bytes) - added by bakcsi 11 years ago.
Test.xml download (8.6 KB) - added by bakcsi 11 years ago.
modules and stack

Download all attachments as: .zip

Change History (13)

Changed 11 years ago by bakcsi

Changed 11 years ago by bakcsi

Changed 11 years ago by bakcsi

modules and stack

comment:1 Changed 11 years ago by bakcsi

  • Keywords thread added
  • Summary changed from wxHTTP Read crash to wxHTTP Read crash in secondary thread on wxGTK

comment:2 Changed 11 years ago by vadz

  • Status changed from new to infoneeded_new

I must be missing something obvious but why doesn't this program end immediately? I don't see anything in its code waiting for the child thread so how exactly is this supposed to work?

comment:3 Changed 11 years ago by bakcsi

  • Status changed from infoneeded_new to new

Well, I'm not that familiar with wxWidgets internals, but I'd guess because it is compiled as a gui program and TestApp::OnInit() returns true. (Of course the program appears only in the process list.)

comment:4 Changed 9 years ago by vadz

Does anybody know of some way to reproduce this problem? AFAICS I need an endless (video) stream to be able to run the example and I don't have one. I think gstreamer could be used to generate it on a network socket but not sure how exactly, does anybody know?

comment:5 Changed 9 years ago by bakcsi

  • Resolution set to fixed
  • Status changed from new to closed

We just reproduced it (SVN rev. num. 65474).
We used the stream as in the attached test.cpp:
http://195.24.42.68/control/faststream.jpg?stream=MxPEG&needlength&fps=25

comment:6 Changed 9 years ago by bakcsi

  • Resolution fixed deleted
  • Status changed from closed to reopened

Sorry, I closed this ticket by mistake...

comment:7 Changed 9 years ago by vadz

  • Status changed from reopened to confirmed

Hmm, first for me it reliably crashes on startup in non-GUI build (i.e. linking with base and net libraries only) because opening the stream fails with strange epoll error. This clearly needs to be debugged too :-(

I also can reproduce the crash when building with GUI, i.e. when additionally linking with the core library. It asserts in both the main and worker threads, for the reference:

(gdb) thr 1
[Switching to thread 1 (Thread 0x7ffff7ec5800 (LWP 28597))]#0  0x00007ffff64eb93b in raise () from /lib/libpthread.so.0
(gdb) bt
#0  0x00007ffff64eb93b in raise () from /lib/libpthread.so.0
#1  0x00007ffff79c225d in wxTrap () at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:1012
#2  0x00007ffff79c234c in wxDefaultAssertHandler (file=..., line=144, func=..., cond=..., msg=...) at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:1037
#3  0x00007ffff79c11bb in wxOnAssert (file=0x7ffff6eddf60 "/home/zeitlin/src/wx/HEAD/src/unix/sockunix.cpp", line=144, func=0x7ffff6eddffe "OnReadWaiting",
    cond=0x7ffff6eddf42 "m_fd != INVALID_SOCKET", msg=0x7ffff6eddf90 "invalid socket ready for reading?") at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:1129
#4  0x00007ffff6eda85f in wxSocketImplUnix::OnReadWaiting (this=0x7fffe80017e0) at /home/zeitlin/src/wx/HEAD/src/unix/sockunix.cpp:144
#5  0x00007ffff7358ee8 in wxSocket_GDK_Input(gpointer, gint, <anonymous enum>) (data=0x7fffe8001858, condition=GDK_INPUT_READ) at /home/zeitlin/src/wx/HEAD/src/gtk/sockgtk.cpp:32
#6  0x00007ffff5522e2f in gdk_io_invoke (source=<value optimized out>, condition=<value optimized out>, data=<value optimized out>) at /tmp/buildd/gtk+2.0-2.12.12/gdk/gdkevents.c:986
#7  0x00007ffff43a17ab in g_main_dispatch (context=0x65ece0) at /home/joss/deb/pkg-gnome/desktop/lenny/build-area/glib2.0-2.16.6/glib/gmain.c:2012
#8  IA__g_main_context_dispatch (context=0x65ece0) at /home/joss/deb/pkg-gnome/desktop/lenny/build-area/glib2.0-2.16.6/glib/gmain.c:2564
#9  0x00007ffff43a4f7d in g_main_context_iterate (context=0x65ece0, block=1, dispatch=1, self=<value optimized out>)
    at /home/joss/deb/pkg-gnome/desktop/lenny/build-area/glib2.0-2.16.6/glib/gmain.c:2645
#10 0x00007ffff43a54ad in IA__g_main_loop_run (loop=0x67bdf0) at /home/joss/deb/pkg-gnome/desktop/lenny/build-area/glib2.0-2.16.6/glib/gmain.c:2853
#11 0x00007ffff58eb837 in IA__gtk_main () at /tmp/buildd/gtk+2.0-2.12.12/gtk/gtkmain.c:1163
#12 0x00007ffff7353db8 in wxGUIEventLoop::Run (this=0x6712d0) at /home/zeitlin/src/wx/HEAD/src/gtk/evtloop.cpp:60
#13 0x00007ffff79c1095 in wxAppConsoleBase::MainLoop (this=0x6337a0) at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:314
#14 0x00007ffff79c04b4 in wxAppConsoleBase::OnRun (this=0x6337a0) at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:255
#15 0x00007ffff7413cba in wxAppBase::OnRun (this=0x6337a0) at /home/zeitlin/src/wx/HEAD/src/common/appcmn.cpp:284
#16 0x00007ffff7a44c9c in wxEntry (argc=@0x7ffff7ddd870, argv=0x630030) at /home/zeitlin/src/wx/HEAD/src/common/init.cpp:472
#17 0x00007ffff7a4516e in wxEntry (argc=@0x7fffffffe16c, argv=0x7fffffffe248) at /home/zeitlin/src/wx/HEAD/src/common/init.cpp:484
#18 0x0000000000409176 in main (argc=1, argv=0x7fffffffe248) at 10720.cpp:20
(gdb) thr 2
[Switching to thread 2 (Thread 0x40800950 (LWP 28607))]#0  0x00007ffff64ed390 in __errno_location () from /lib/libpthread.so.0
(gdb) bt
#0  0x00007ffff64ed390 in __errno_location () from /lib/libpthread.so.0
#1  0x00007ffff7a78e53 in wxString::ToULong (this=0x407f5380, pVal=0x407f5128, base=10) at /home/zeitlin/src/wx/HEAD/src/common/string.cpp:1698
#2  0x00007ffff7ae6283 in wxStackWalker::InitFrames (this=0x407febf0, arr=0x407f5570, n=20, addresses=0x7ffff7ddfac8, syminfo=0x7fffe80032f8) at /home/zeitlin/src/wx/HEAD/src/unix/stackwalk.cpp:273
#3  0x00007ffff7ae6898 in wxStackWalker::ProcessFrames (this=0x407febf0, skip=5) at /home/zeitlin/src/wx/HEAD/src/unix/stackwalk.cpp:190
#4  0x00007ffff7ae6ade in wxStackWalker::Walk (this=0x407febf0, skip=2, maxDepth=20) at /home/zeitlin/src/wx/HEAD/src/unix/stackwalk.cpp:303
#5  0x00007ffff79c2e02 in wxAppTraitsBase::GetAssertStackTrace (this=0x630050) at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:953
#6  0x00007ffff79c2fb6 in wxAppTraitsBase::ShowAssertDialog (this=0x630050, msgOriginal=...) at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:874
#7  0x00007ffff73672d3 in wxGUIAppTraits::ShowAssertDialog (this=0x630050, msg=...) at /home/zeitlin/src/wx/HEAD/src/gtk/utilsgtk.cpp:397
#8  0x00007ffff79c1717 in ShowAssertDialog (file=..., line=55, func=..., cond=..., msgUser=..., traits=0x630050) at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:1253
#9  0x00007ffff79c1843 in wxAppConsoleBase::OnAssertFailure (this=0x6337a0, file=0x7fffe8002fb0 L"/home/zeitlin/src/wx/HEAD/src/common/socketiohandler.cpp", line=55,
    func=0x7fffe8002f60 L"Install_Callback", cond=0x7fffe8002f00 L"socket->m_fd != -1", msg=0x7fffe8002e60 L"shouldn't be called on invalid socket")
    at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:758
#10 0x00007ffff732c1ee in wxApp::OnAssertFailure (this=0x6337a0, file=0x7fffe8002fb0 L"/home/zeitlin/src/wx/HEAD/src/common/socketiohandler.cpp", line=55, func=0x7fffe8002f60 L"Install_Callback",
    cond=0x7fffe8002f00 L"socket->m_fd != -1", msg=0x7fffe8002e60 L"shouldn't be called on invalid socket") at /home/zeitlin/src/wx/HEAD/src/gtk/app.cpp:489
#11 0x00007ffff79c246f in wxDefaultAssertHandler (file=..., line=55, func=..., cond=..., msg=...) at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:1053
#12 0x00007ffff79c11bb in wxOnAssert (file=0x7ffff6edde08 "/home/zeitlin/src/wx/HEAD/src/common/socketiohandler.cpp", line=55, func=0x7ffff6eddeb0 "Install_Callback",
    cond=0x7ffff6edde86 "socket->m_fd != -1", msg=0x7ffff6edde60 "shouldn't be called on invalid socket") at /home/zeitlin/src/wx/HEAD/src/common/appbase.cpp:1129
#13 0x00007ffff6eda0cc in wxSocketFDBasedManager::Install_Callback (this=0x7ffff70ef880, socket_=0x7fffe80017e0, event=wxSOCKET_OUTPUT) at /home/zeitlin/src/wx/HEAD/src/common/socketiohandler.cpp:54
#14 0x00007ffff6eda6d8 in wxSocketImplUnix::DoEnableEvents (this=0x7fffe80017e0, flags=3, enable=true) at /home/zeitlin/src/wx/HEAD/src/unix/sockunix.cpp:111
#15 0x00007ffff6edaa80 in wxSocketImplUnix::EnableEvents(int) () from /home/zeitlin/build/wx-gtkud/lib/libwx_baseu_net-2.9.so.2
#16 0x00007ffff6edaabd in wxSocketImplUnix::UnblockAndRegisterWithEventLoop() () from /home/zeitlin/build/wx-gtkud/lib/libwx_baseu_net-2.9.so.2
#17 0x00007ffff6ed0bb9 in wxSocketImpl::PostCreation (this=0x7fffe80017e0) at /home/zeitlin/src/wx/HEAD/src/common/socket.cpp:368
#18 0x00007ffff6ed368f in wxSocketImpl::CreateClient (this=0x7fffe80017e0, wait=true) at /home/zeitlin/src/wx/HEAD/src/common/socket.cpp:446
#19 0x00007ffff6ed3e5f in wxSocketClient::DoConnect (this=0x407ff800, remote=..., local=0x0, wait=true) at /home/zeitlin/src/wx/HEAD/src/common/socket.cpp:1957
#20 0x00007ffff6ed06aa in wxSocketClient::Connect (this=0x407ff800, remote=..., wait=true) at /home/zeitlin/src/wx/HEAD/src/common/socket.cpp:1977
#21 0x00007ffff6ec0edd in wxProtocol::Connect (this=0x407ff800, addr=...) at /home/zeitlin/src/wx/HEAD/include/wx/protocol/protocol.h:66
#22 0x00007ffff6ec3e25 in wxHTTP::GetInputStream (this=0x407ff800, path=...) at /home/zeitlin/src/wx/HEAD/src/common/http.cpp:482
#23 0x0000000000408f68 in VideoIP::Entry (this=0x67b9d0) at 10720.cpp:47
#24 0x00007ffff7af1a73 in wxThreadInternal::PthreadStart (thread=0x67b9d0) at /home/zeitlin/src/wx/HEAD/src/unix/threadpsx.cpp:854
#25 0x00007ffff7af1e99 in wxPthreadStart (ptr=0x67b9d0) at /home/zeitlin/src/wx/HEAD/src/unix/threadpsx.cpp:804
#26 0x00007ffff64e3fc7 in start_thread () from /lib/libpthread.so.0
#27 0x00007ffff625964d in clone () from /lib/libc.so.6
#28 0x0000000000000000 in ?? ()

Something is indeed clearly wrong here but I ran out of time to debug it today...

comment:8 Changed 8 years ago by kraymer

  • Cc mail@… added

comment:9 Changed 6 years ago by vadz

This is probably related to or even the same as #12886. Not that it really helps...

comment:10 Changed 2 weeks ago by vadz

  • Resolution set to fixed
  • Status changed from confirmed to closed

I think this was fixed by e18c8fd29a10b1b87ea5cff7c5b3a16fe5b32690 4+ years ago (so part of 3.1.0 and later), which was also backported to 3.0.3 as e62173c4798a7e4f23181ef3325e7ed2f5cc3cf6.

Please reopen if it still can be reproduced.

Note: See TracTickets for help on using tickets.