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
Individually commenting out the 15 single-point Datachecks + the HighwaySegment ctor = crashes continue.
per-route datachecks = crashes continue.
label_too_long = crashes continue.
WaypointQuadtree::insert = crashes continue.
std::cout << '.' << std::flush; <--There's no mutex around this. All threads can just go crazy & do whatever.
Still crashes! :(
anything else?
Verbosity
Crashes when reading usaca are very common. Add debug text; see if it hangs on a specific route.
Could also be whatever's processed concurrently. Need to know what systems are in flight at any given time.
create static std::vector<HighwaySystem*> HighwaySystem::in_flight(Args::numthreads,0); and have ReadWptThread write to & display it.
LOL disregard that last post.
I ran my new code without compiling it first. :P
Workaround to iterate thru the systems list without a mutex:
Tried it anyway. No luck. Still crashes.
Now what?
Gotta run 2 threads and observe what both are doing when the crash occurs, without producing an overly huge log file in the process.
This means filtering debug text for the 2 systems I expect to be in progress at the time.
It's usually usaal & usaca, so I'm filtering for that. This last time with the new code, got usafl & usaca.
Gonna keep going till I get usaal & usaca, and see what I can see. Better yet, set up variants to capture both combos, and see which brings results first. Even betterer,, set up one to capture all 3. The log file will be bigger, but not huge.
One of the most frustrating things in my long-ago experiences debugging parallel code is that the fact you put in logging or write files to track down problems can change the timing and cause problems that weren't evident originally as well as mask problems you might have seen previously so they look like they're fixed...until you remove the debug code.
Add verbosity to everything that happens during Route::read_wpt, to see what both threads are doing at the time of the crash, and if there's something consistent. This may not be the most helpful if the effects of whatever goes amok aren't immediate.
Add verbosity to everything that happens during Route::read_wpt, to see what both threads are doing at the time of the crash, and if there's something consistent. This may not be the most helpful if the effects of whatever goes amok aren't immediate.
I don't see anything consistent. This approach is not helpful.
Doing this. Still though, need to go down 2 rabbit holes in parallel: #443 (comment):
WaypointQuadtree::insert = crashes continue.
Crashes continue in the DataProcessing variations where I'm adding debug text to the existing code.
In TMMinimal however, after removing loads of other code, removing WaypointQuadtree::insert stops the crashes.
So there are at least 2 causes of crashes:
WaypointQuadtree::insert (what part of it?)
It's not a std::recursive_mutex problem; reverting ef1894f did not help.
In TMMinimal however, after removing loads of other code, removing WaypointQuadtree::insert stops the crashes.
Or not. It could be that it just made them a lot less frequent. TMMinimal2 first removes a ton of code, but not as much as TMMinimal. Testing out removing WaypointQuadtree::insert from a range of commits, some ran 430, 1009, 437, 1952 or 2033 times before crashing. One of them is still going @ 5007, and expected to crash eventually.
So there are at least 2 causes of crashes:
Could be 2 causes, could be just 1. It may be that our Something else TBD throws the ball, and WaypointQuadtree::insert is somehow better able to catch it.
This will take a lot of patience. If i'm not concerned with poring thru siteupdate.log anymore, hopefully >2 threads can bring on the crashes quicker. If I end up needing too many threads, I'll use lab3 rather than noreaster.
TMMinimal2@d646f31 crashed on noreaster, after 2051 passes. That's good. I want to see that.
And then there's its child commit, which cuts out some unused code.
At this point in TMMinimal2, no TravelerList objects are ever created. The few non-static members left in the class are just there because they're referenced by some other part of the code (Route, and... HighwaySegment?) I'd yet to snip out.
TravelerList is only being kept around for its 2 remaining static members:
Traverlist::mtx, which has been repurposed as a terminal mutex for keeping the debug text readable.
Travelerlist::ids, analogous to traveler_ids in siteupdate.py. The list of traveler ids is still populated in main() and takes up some memory, altering however subtly the operating environment once we start reading wpts.
I ran this code, and 3 of its child commits, in a loop via untilcrash.sh, approx 5100 times. 4 threads on noreaster, 6 on my BSD 13.0 machine.
So, what's different?
A few static members of Travelerlist are gone, that took up a whopping 112 B.
5 functions are gone, including the TravelerList ctor. Even if they weren't called, these instructions all took up however much memory. Right?
It'd appear that getting this stuff out of memory changes where everything else sits in memory afterward, getting it out of the "danger zone". Our pointers there don't get mangled, and we don't observe the bug.
This doesn't solve the problem; it only masks the symptom.
I should be able to remove any number of things from TMMinimal2@d646f31, doesn't particularly matter what, and similarly sweep the problem under the rug.
This has to be a bug in BSD clang.
Tens of thousands of runs built with clang G++ on Linux & I've not seen these crashes once.
Built with clang... Hm. Maybe only about 1000? Time to run untilcrash.sh (f8c262e) on lab1 & lab2 to be absolutely sure...
It'd be nice to be able to submit a bug report to the developers, if I can ever isolate it. Of course, this means a minimal version of the program with only what's necessary to observe the crash. No good pointing them toward 7500+ lines of siteupdate and saying Have fun finding the bug!
I fear that I'll only sweep the problem under the rug before isolating it...
What next?
Maybe go back to the first TMMinimal (somewhere around ac6eaf) and leave WaypointQuadtree::insert in, making the crashes easier to observe, more frequent. Continue removing code, making sure it still crashes as long as it can.
In TMMinimal however, after removing loads of other code, removing WaypointQuadtree::insert stops the crashes.
Or not. It could be that it just made them a lot less frequent.
A hell of a lot less frequent.
TMMinimal2 first removes a ton of code, but not as much as TMMinimal. Testing out removing WaypointQuadtree::insert from a range of commits, some ran 430, 1009, 437, 1952 or 2033 times before crashing. One of them is still going @ 5007, and expected to crash eventually.
2 minutes after my last post, it finally crashed. After 10056 passes.
This will take a lot of patience.
And so there's an indication of just how much patience...
Maybe go back to the first TMMinimal (somewhere around ac6eaf) and leave WaypointQuadtree::insert in, making the crashes easier to observe, more frequent. Continue removing code, making sure it still crashes as long as it can.
For the sake of sanity, expedience, and the ability to observe crashes with any kind of regularity, this looks like a better option than continuing down the TMMinimal2 road. Edit: Tracking progress here. Thankfully, the crashes are happening really quickly. For now at least...
Progress has been steady.
Everything after the Reading waypoints for all routes loop has been removed except for the Total run time text, in order to keep untilcrash.sh working.
Everything before it has been removed, except what's necessary to set it up.
The total line count of all .h + .cpp files is down to 731 from 7505.
Waypoint class
Unnecessary variables removed from all classes except Waypoint. Changes to sizeof(Waypoint) could have big effects on where everything sits in memory, and possibly mask the problem. Best be cautious here.
Incidentally, sizeof(Waypoint) differs between FreeBSD & Ubuntu when compiled with clang (haven't looked at CentOS, and I wanna say g++ is the same on Ubuntu). Padding out the Waypoint structure to 192 bytes = it still crashes, unsurprsingly.
Now the real fun begins...
...hacking away at parts of the loop itself, seeing what crashes and what doesn't.
First thing to go will be the set of all .wpt filenames in hwy_data/ used for tracking unprocessedwpts. I can cut out a good amount of code with minimal impact; early tests indicate I'll still see crashes.
TMMinimal@bdf9590 crashed, even if it took 13191 passes to do so.
This means losing WaypointQuadtree = we still get crashes.
TMMinimal@d18a904
This means losing everything butWaypointQuadtree and what's absolutely necessary to keep the ReadWptThread loop running = we still get crashes.
This suggests that whatever's happening is during the barebones setup & ReadWptThread loop, and that removing WaypointQuadtree from d18a904 (yieldingTMMinimal@9df3607) would still cause crashes, even if it takes thousands and thousands of passes to observe them.
Just started testing on noreaster:
siteupdate -t 4
siteupdate -t 1
siteupdateST
Thinking back to C++ site update to production #375 (comment), remember that even siteupdateST crashed. We're seeing the same... (is it a cause or a symptom?) now, of a pointer's value mysteriously decreasing by 0x900000000. Single-threaded crashes could still be a thing, if I'm patient & hang around long enough to observe them.
Will reverting d6da523 make crashes more frequent & easier to observe? Maybe, maybe not. Testing 2t, 1t & ST.
Or could std::list<Waypoint*> *colocated having been after a bubble of empty space between unsigned int point_num and std::string label have been a factor? Reverting 383f269 & trying that too. 2t, 1t & ST.
Now to sit back and wait. For... however long it takes.
If I still see crashes, it might be time to go to https://llvm.org/docs/HowToSubmitABug.html ...
TMMinimal is down to 437 lines; hopefully that's not too much to wade through. :)
Still haven't looked at FreeBSD 11.4. Now's a good time... Edit: Or maybe try out valgrind...
In my days of more heavy duty parallel programming, we had some high-end tools available to help find memory errors, including TotalView, which appears to remain in existence: https://totalview.io/products/totalview
It doesn't look like there's a FreeBSD version, however.
Crashes when reading usaca are very common. Add debug text; see if it hangs on a specific route.
Oh man. I came so close. It's difficult to identify a specific route via siteupdate.log because we may be a few routes farther along in the process before the crash happens (and I was focusing on what happens at the Waypoint level & missing the bigger picture).
I opened ca.ca061pos in the HB. May have even thrown it into GHex at one point. Must not have done a text editor though, or I would have seen the blank line at the beginning of the file.
There are 2 other offending files -- rou.dk142j, and it was pse.h060 that finally tipped me off.
A .wpt file is first slurped into core as big-ol' char array. And then,
char * endchar = lines[l+1]-2; // -2 skips over the 0 inserted while splitting wptdata into lines
• lines[1] is wptdata+1.
• Thus endchar is wptdata-1.
BLAMMO! A pointer to one byte before the beginning of the file in memory!
Now let's say we have a memory address stored there, like 0x912e2a0e0.
Let's put these 8 bytes in little-endian order: e0 a0 e2 12 09 00 00 00.
Next line,
while (*endchar == 0) endchar--; // skip back more for CRLF cases, and lines followed by blank lines
The incorrect assumption is that we're in the middle of the file somewhere.
This skips us back past the three 00s, putting us at the 09. Which is ascii TAB...
...and gets zeroed out.
And we proceed back through memory, to potentially do more damage. This explains the couplefew pointer values I saw with a high order 0x920 zeroed out; 0x20 is ascii Space.
(Worth noting that the g++ version doesn't store Waypoints in this memory range -- more 0x84####### ballpark. Could this be why it doesn't crash?)
Yup. For clang on Linux, either this is still the case, with pointers stored out of 0x9######## range, or I just never happened to observe the problem in the moderate number of runs I did with clang.
Anyway!
Now that the problem is finally identified, fixing it will be very easy.
I see a couple ways to do it; just need to decide which is better.
So I was like "O HAY, the TravelerList constructor processes lines the same way; that'll need a fix too!" Oh look. It already got one a year ago.
If only I'd made the same connection back then... 🤣
And it look like the Python version doesn't care about a blank line because it breaks the file into lines first, strips off whitespace, and ignores any line that's empty after that.
And as for how it does the splitting into lines & stripping whitespace, well...
This kind of madness is the reason some languages don't do pointer arithmetic. :D
I feel like my C class in the fall and my Programming Languages class whenever I can offer that next need to use this bug as a case study for the dangers of a language trusting the programmer too much.
Ha. Guess what I'm doing.
I've fixed stuff like this before...
How come I've never seen a crash like in #402 when reading nmpfps.log? It must depend on what's in memory before line.data()...
Activity
yakra commentedon Jun 26, 2021
Route::read_wpt: Comment out...
std::cout << '.' << std::flush;<--There's no mutex around this. All threads can just go crazy & do whatever.Still crashes! :(
Verbosity
Could also be whatever's processed concurrently. Need to know what systems are in flight at any given time.
std::vector<HighwaySystem*> HighwaySystem::in_flight(Args::numthreads,0);and have ReadWptThread write to & display it.yakra commentedon Jun 27, 2021
yakra commentedon Jun 28, 2021
LOL disregard that last post.
I ran my new code without compiling it first. :P
Workaround to iterate thru the systems list without a mutex:
Tried it anyway. No luck. Still crashes.
Now what?
Gotta run 2 threads and observe what both are doing when the crash occurs, without producing an overly huge log file in the process.
This means filtering debug text for the 2 systems I expect to be in progress at the time.
It's usually usaal & usaca, so I'm filtering for that. This last time with the new code, got usafl & usaca.
Gonna keep going till I get usaal & usaca, and see what I can see.
Better yet, set up variants to capture both combos, and see which brings results first.
Even betterer,, set up one to capture all 3. The log file will be bigger, but not huge.
jteresco commentedon Jun 28, 2021
One of the most frustrating things in my long-ago experiences debugging parallel code is that the fact you put in logging or write files to track down problems can change the timing and cause problems that weren't evident originally as well as mask problems you might have seen previously so they look like they're fixed...until you remove the debug code.
yakra commentedon Jun 29, 2021
Taking 2 different approaches in parallel:
Dead branch:
debug@ b31046b78fa373a5e5f028705ae1a6f4481b0ddc superseded by 36abf08yakra commentedon Jun 30, 2021
I don't see anything consistent. This approach is not helpful.
Doing this. Still though, need to go down 2 rabbit holes in parallel:
#443 (comment):
Crashes continue in the DataProcessing variations where I'm adding debug text to the existing code.
In TMMinimal however, after removing loads of other code, removing WaypointQuadtree::insert stops the crashes.
So there are at least 2 causes of crashes:
It's not a std::recursive_mutex problem; reverting ef1894f did not help.
yakra commentedon Jul 1, 2021
Or not. It could be that it just made them a lot less frequent.
TMMinimal2 first removes a ton of code, but not as much as TMMinimal. Testing out removing WaypointQuadtree::insert from a range of commits, some ran 430, 1009, 437, 1952 or 2033 times before crashing. One of them is still going @ 5007, and expected to crash eventually.
Could be 2 causes, could be just 1. It may be that our Something else TBD throws the ball, and WaypointQuadtree::insert is somehow better able to catch it.
This will take a lot of patience. If i'm not concerned with poring thru siteupdate.log anymore, hopefully >2 threads can bring on the crashes quicker. If I end up needing too many threads, I'll use lab3 rather than noreaster.
To be continued...
yakra commentedon Jul 2, 2021
Grawlix.
Have I linked to http://www.catb.org/jargon/html/H/heisenbug.html yet? If not, doing so now.
(Edit: Yes.)
TMMinimal2@d646f31 crashed on noreaster, after 2051 passes. That's good. I want to see that.
And then there's its child commit, which cuts out some unused code.
At this point in TMMinimal2, no TravelerList objects are ever created. The few non-static members left in the class are just there because they're referenced by some other part of the code (Route, and... HighwaySegment?) I'd yet to snip out.
TravelerList is only being kept around for its 2 remaining static members:
traveler_idsin siteupdate.py. The list of traveler ids is still populated in main() and takes up some memory, altering however subtly the operating environment once we start reading wpts.I ran this code, and 3 of its child commits, in a loop via
untilcrash.sh, approx 5100 times. 4 threads on noreaster, 6 on my BSD 13.0 machine.So, what's different?
It'd appear that getting this stuff out of memory changes where everything else sits in memory afterward, getting it out of the "danger zone". Our pointers there don't get mangled, and we don't observe the bug.
This doesn't solve the problem; it only masks the symptom.
I should be able to remove any number of things from TMMinimal2@d646f31, doesn't particularly matter what, and similarly sweep the problem under the rug.
This has to be a bug in BSD clang.
clangG++ on Linux & I've not seen these crashes once.untilcrash.sh(f8c262e) on lab1 & lab2 to be absolutely sure...It'd be nice to be able to submit a bug report to the developers, if I can ever isolate it. Of course, this means a minimal version of the program with only what's necessary to observe the crash. No good pointing them toward 7500+ lines of siteupdate and saying Have fun finding the bug!
I fear that I'll only sweep the problem under the rug before isolating it...
What next?
Maybe go back to the first TMMinimal (somewhere around
ac6eaf) and leave WaypointQuadtree::insert in, making the crashes easier to observe, more frequent. Continue removing code, making sure it still crashes as long as it can.crash when Sorting waypoints in Quadtree #442 (comment)
Have yet to do this. With any luck, the bug was introduced to the compiler between FreeBSD 11.4 & 12.2.
yakra commentedon Jul 2, 2021
#443 (comment)
A hell of a lot less frequent.
2 minutes after my last post, it finally crashed. After 10056 passes.
And so there's an indication of just how much patience...
#443 (comment)
For the sake of sanity, expedience, and the ability to observe crashes with any kind of regularity, this looks like a better option than continuing down the TMMinimal2 road.
Edit: Tracking progress here. Thankfully, the crashes are happening really quickly. For now at least...
yakra commentedon Jul 3, 2021
TMMinimal
Progress has been steady.
Everything after the Reading waypoints for all routes loop has been removed except for the Total run time text, in order to keep untilcrash.sh working.
Everything before it has been removed, except what's necessary to set it up.
The total line count of all .h + .cpp files is down to 731 from 7505.
Waypoint class
Unnecessary variables removed from all classes except Waypoint. Changes to
sizeof(Waypoint)could have big effects on where everything sits in memory, and possibly mask the problem. Best be cautious here.Incidentally,
sizeof(Waypoint)differs between FreeBSD & Ubuntu when compiled with clang (haven't looked at CentOS, and I wanna say g++ is the same on Ubuntu). Padding out the Waypoint structure to 192 bytes = it still crashes, unsurprsingly.Now the real fun begins...
...hacking away at parts of the loop itself, seeing what crashes and what doesn't.
First thing to go will be the set of all .wpt filenames in hwy_data/ used for tracking unprocessedwpts. I can cut out a good amount of code with minimal impact; early tests indicate I'll still see crashes.
yakra commentedon Jul 4, 2021
This means losing
WaypointQuadtree= we still get crashes.This means losing everything but
WaypointQuadtreeand what's absolutely necessary to keep theReadWptThreadloop running = we still get crashes.This suggests that whatever's happening is during the barebones setup &
ReadWptThreadloop, and that removingWaypointQuadtreefromd18a904(yieldingTMMinimal@9df3607) would still cause crashes, even if it takes thousands and thousands of passes to observe them.Just started testing on noreaster:
std::list<Waypoint*> *colocatedhaving been after a bubble of empty space betweenunsigned int point_numandstd::string labelhave been a factor? Reverting 383f269 & trying that too. 2t, 1t & ST.Now to sit back and wait. For... however long it takes.
If I still see crashes, it might be time to go to https://llvm.org/docs/HowToSubmitABug.html ...
TMMinimal is down to 437 lines; hopefully that's not too much to wade through. :)
Still haven't looked at FreeBSD 11.4. Now's a good time...
Edit: Or maybe try out valgrind...
jteresco commentedon Jul 5, 2021
In my days of more heavy duty parallel programming, we had some high-end tools available to help find memory errors, including TotalView, which appears to remain in existence: https://totalview.io/products/totalview
It doesn't look like there's a FreeBSD version, however.
yakra commentedon Jul 5, 2021
Giving valgrind a go on lab3.
yakra commentedon Jul 5, 2021
OK. Wow. I think I've got it.
I'll post more when I can put a sentence together.
First, sleep.
jteresco commentedon Jul 5, 2021
Good! Awaiting the big reveal of what you've found out!
yakra commentedon Jul 5, 2021
#443 (comment)
Oh man. I came so close. It's difficult to identify a specific route via siteupdate.log because we may be a few routes farther along in the process before the crash happens (and I was focusing on what happens at the
Waypointlevel & missing the bigger picture).I opened ca.ca061pos in the HB. May have even thrown it into GHex at one point. Must not have done a text editor though, or I would have seen the blank line at the beginning of the file.
There are 2 other offending files -- rou.dk142j, and it was pse.h060 that finally tipped me off.
A .wpt file is first slurped into core as big-ol'
chararray. And then,DataProcessing/siteupdate/cplusplus/classes/Route/read_wpt.cpp
Lines 36 to 41 in b3f2440
Paraphrasing for expository purposes, with
whileinstead offor:The loop repeats starting at
wptdata+1--cis the start of the first waypoint label, andlines[1]becomeswptdata+1. SFSG.The trouble starts when we go to strip whitespace from the end of
lines[0]:DataProcessing/siteupdate/cplusplus/classes/Route/read_wpt.cpp
Line 53 in b3f2440
•
lines[1]iswptdata+1.• Thus
endchariswptdata-1.BLAMMO! A pointer to one byte before the beginning of the file in memory!
Now let's say we have a memory address stored there, like
0x912e2a0e0.Let's put these 8 bytes in little-endian order:
e0 a0 e2 12 09 00 00 00.Next line,
DataProcessing/siteupdate/cplusplus/classes/Route/read_wpt.cpp
Line 54 in b3f2440
The incorrect assumption is that we're in the middle of the file somewhere.
This skips us back past the three
00s, putting us at the09. Which is ascii TAB...DataProcessing/siteupdate/cplusplus/classes/Route/read_wpt.cpp
Lines 55 to 58 in b3f2440
...and gets zeroed out.
And we proceed back through memory, to potentially do more damage. This explains the couplefew pointer values I saw with a high order
0x920zeroed out;0x20is ascii Space.Why did I never see this on Linux?
#375 (comment)
Yup. For clang on Linux, either this is still the case, with pointers stored out of
0x9########range, or I just never happened to observe the problem in the moderate number of runs I did with clang.Anyway!
Now that the problem is finally identified, fixing it will be very easy.
I see a couple ways to do it; just need to decide which is better.
yakra commentedon Jul 6, 2021
So I was like "O HAY, the TravelerList constructor processes lines the same way; that'll need a fix too!"
Oh look. It already got one a year ago.
If only I'd made the same connection back then... 🤣
Cope with blank lines at beginning of .wpt files
jteresco commentedon Jul 6, 2021
And it look like the Python version doesn't care about a blank line because it breaks the file into lines first, strips off whitespace, and ignores any line that's empty after that.
yakra commentedon Jul 6, 2021
Yup. C++ does the same thing too -- just not 100% successfully till now. :)
DataProcessing/siteupdate/cplusplus/classes/Route/read_wpt.cpp
Line 59 in b3f2440
DataProcessing/siteupdate/cplusplus/classes/Route/read_wpt.cpp
Line 54 in e90d92c
The relevant part of the diff is here.
And as for how it does the splitting into lines & stripping whitespace, well...
This kind of madness is the reason some languages don't do pointer arithmetic. :D
jteresco commentedon Jul 6, 2021
I feel like my C class in the fall and my Programming Languages class whenever I can offer that next need to use this bug as a case study for the dangers of a language trusting the programmer too much.
yakra commentedon Jul 7, 2021
It made me start looking into Rust.
Meanwhile, as the results of valgrind are starting to come in, see I'm doing similar stuff elsewhere, even if not with pointers.
DataProcessing/siteupdate/cplusplus/siteupdate.cpp
Lines 268 to 275 in 1e29902
Quote from http://cplusplus.com/reference/string/string/back/
Ha. Guess what I'm doing.
I've fixed stuff like this before...
How come I've never seen a crash like in #402 when reading nmpfps.log? It must depend on what's in memory before line.data()...
yakra commentedon Jul 8, 2021
#443 (comment)
Still needs a fix, actually.
can still result in
endcharbeing initialized to one byte before the beginning of the file.