OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Crash in ReaderWriterCURL::readFile when used with DatabasePager


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
hartwigw
Appreciator


Joined: 20 Mar 2009
Posts: 128

PostPosted: Sun Dec 17, 2017 11:46 pm    Post subject:
Crash in ReaderWriterCURL::readFile when used with DatabasePager
Reply with quote

Hi,

I am using PagedLOD together with a pseudo-loader to load files via the network. To load the files the ReaderWriterCURL class is used.

The database pager is set up with one general and one HTTP thread. This means that the ReaderWriterCURL::readFile(ObjectType, const std::string&, const osgDB::ReaderWriter::Options*) (and WriteFile) method is always called from the same thread!

In ReaderWriterCURL::readFile the class method getEasyCurl() is used to get a reference to an EasyCurl object. And always the same EasyURL object is returned because it is always the same thread that is calling getEasyCurl().

The problem is (seems to be) that although the ReaderWriterCURL::readFile is used by the same thread (see below) it can happen that different instances of ReaderWriterCURL::readFile are running in parallel (verified by debug output). But this means that these instances use the SAME EasyCURL object! And this will lead to a crash as the stream object is gone while EasyCurl is trying to write to it.
I do not know how this can happen. Perhaps OpenThreads::Thread::CurrentThread() just returns a wrong thread number (in getEasyCurl)?

For testing purposes I replaced the call to getEasyCurl in ReaderWriterCURL::readFile with osg::ref_ptr<EasyCurl> easyCurl and did the corresponding replacements ("." replaced by "->") and everything went smoothly.

I do not know the purpose of getEasyCur() using a map of EasyCurl objects as this method is only used in ReaderWriterCURL::readFile and writeFile. The only thing that has to be prevented is that curl_easy_init() is called in parallel. But this can also be achieved by returning an osg::ref_ptr<EasyCurl> object in combination with a lock.

Awaiting your comments!

Cheers,
Hartwig
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Mon Dec 18, 2017 8:18 am    Post subject:
Crash in ReaderWriterCURL::readFile when used with DatabasePager
Reply with quote

HI Hartwing,

Which version of the OSG are you testing under?

Robert.

On 17 December 2017 at 23:46, Hartwig Wiesmann
<> wrote:
Quote:
Hi,

I am using PagedLOD together with a pseudo-loader to load files via the network. To load the files the ReaderWriterCURL class is used.

The database pager is set up with one general and one HTTP thread. This means that the ReaderWriterCURL::readFile(ObjectType, const std::string&, const osgDB::ReaderWriter::Options*) (and WriteFile) method is always called from the same thread!

In ReaderWriterCURL::readFile the class method getEasyCurl() is used to get a reference to an EasyCurl object. And always the same EasyURL object is returned because it is always the same thread that is calling getEasyCurl().

The problem is (seems to be) that although the ReaderWriterCURL::readFile is used by the same thread it can happen that different instances of ReaderWriterCURL::readFile are running in parallel (verified by debug output). But this means that these instances use the SAME EasyCURL object! And this will lead to a crash.

For testing purposes I replaced the call to getEasyCurl in ReaderWriterCURL::readFile with osg::ref_ptr<EasyCurl> easyCurl and did the corresponding replacements ("." replaced by "->") and everything went smoothly.

I do not know the purpose of getEasyCur() using a map of EasyCurl objects as this method is only used in ReaderWriterCURL::readFile and writeFile. The only thing that has to be prevented is that curl_easy_init() is called in parallel. But this can also be achieved by returning an osg::ref_ptr<EasyCurl> object in combination with a lock.

Awaiting your comments!

Cheers,
Hartwig

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72591#72591








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
hartwigw
Appreciator


Joined: 20 Mar 2009
Posts: 128

PostPosted: Mon Dec 18, 2017 5:41 pm    Post subject:
Reply with quote

Hi Robert,

I am using 3.4.2. I already checked GIT but could not find any modification in ReaderWriterCurl that is relevant.

Thank you!

Cheers,
Hartwig
Back to top
View user's profile Send private message
hartwigw
Appreciator


Joined: 20 Mar 2009
Posts: 128

PostPosted: Mon Dec 18, 2017 6:01 pm    Post subject:
Reply with quote

Hi Robert,

I did some further investigations: I added in ReaderWriterCURL::readFile an atomic counter and stopped in the debugger whenever the atomic counter reaches 2 (means 2 threads are running at the same time an instance of ReaderWriterCURL::readFile).

The debugger showed clearly that there are two threads running but OpenThreads::Thread::CurrentThread() always returned the same pointer to Thread. Therefore, getEasyCurl() does not work correctly.

PS: I do not know if OpenThreads is broken on macOS?! I compiled OpenThreads with

Code:
#define _OPENTHREADS_ATOMIC_USE_MUTEX 1


but this should actually not matter.

Cheers,
Hartwig
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts osgText 3.6.3 crash Trajce Nikolov NICK General 2 Wed Sep 12, 2018 12:25 pm View latest post
No new posts Crash when using LineSegmentIntersector sbrkopac General 5 Thu Aug 02, 2018 10:03 pm View latest post
No new posts [Crash issue] no error info even set ... pwang General 1 Sun Jul 29, 2018 1:20 pm View latest post
No new posts [Crash issue] How to add&remove d... pwang General 2 Thu Jul 26, 2018 10:10 am View latest post
No new posts RayIntersector with KdTree causes a c... Ale General 15 Thu Jul 26, 2018 9:33 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP