Skip to content

crash when Writing near-miss point merged wpt files #44

Closed

Description

@yakra
[23.0] Writing near-miss point merged wpt files.
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_M_create
  • Observed with Route__read_wpt__strtok (and, by necessity, Waypoint__strtok)
  • Not Also observed with the new Waypoint.cpp using sprintf
  • Did switching to sprintf fix something, or did I just not happen to observe the problem?
    • Did not fix. I just didn't observe the problem.
  • Could it be the old trail0 function, trying to access std::string::data on an empty string?
    • How would it even be receiving an empty string?
    • No need to worry. Problem still exists after removal of trail0

Activity

  1. yakra commented on Jan 16, 2019

    @yakra
    OwnerAuthor
    [22.7] Writing near-miss point merged wpt files.
    terminate called after throwing an instance of 'std::bad_alloc'
      what():  std::bad_alloc
    

    While the error in the OP is pretty common, I've only ever seen this once IIRC.

  2. added
    nmps
    on Jan 21, 2019
  3. yakra commented on Jan 23, 2019

    @yakra
    OwnerAuthor

    This just doesn't seem to make sense.
    All strings involved are pretty well-defined, with no opportunities to have zero, negative, or humongous lengths. Just shouldn't be happening, but here it is...

    To unpack this a bit...

    1. First, when still in single-threaded operation, Route objects (each containing a minimum of 5 strings + any alt_route_names) are copied into the all_routes list. Would this present a problem with -t 1? Possibly try pointers.
    2. Second, args.nmpmergepath is passed to NmpMergedThread. This can be passed as a pointer instead.
    3. New Route object created from front of list. Again, try pointers?
    4. nmpmergepath + "/" + r.region->code passed to r.write_nmp_merged. Can't pass by reference here, obviously.
    5. filename gets concatenated a few times.
    6. for (std::string a : w.data->alt_labels) &a instead
    7. std::to_string with latitude & longitude. sprintf
  4. yakra commented on Jan 23, 2019

    @yakra
    OwnerAuthor

    Addressed points 2 and 6. Crashes are still happening, 4 runs out of 40.

  5. yakra commented on Jan 23, 2019

    @yakra
    OwnerAuthor

    Point 7 -> crashes are still happening, 6 attempts out of 100. Comparable to the 5/100 I got before attempting changes.

  6. yakra commented on Jan 24, 2019

    @yakra
    OwnerAuthor

    Points 1 & 3 -> no crashes while Writing near-miss point merged wpt files, in 100 runs.

    Putting std::to_string back (reverting point 7) would mean more clean & concise code. Seems to run a bit faster too.
    Just gotta do 100 trials to make sure the bugs don't creep back in. :)

    Edit: And it's back. Attempt 15 of 29 so far. This means returning to sprintf, and doing even more trials to make sure things work.

  7. yakra commented on Jan 24, 2019

    @yakra
    OwnerAuthor

    Still crashes. 3 times out of 400.
    No Bash output observed, so I can't confirm whether the issue is still std::length_error / basic_string::_M_create. If it is, it's points 4 & 5, path & filename. Feh.
    I'll wait till I catch it in the act again...

  8. yakra commented on Jan 25, 2019

    @yakra
    OwnerAuthor

    script captured all bash output for 400 runs. 7 crashes while reading WPTs; one crash writing nmp_merged. Not std::length_error / basic_string::_M_create, but a core dump similar to what's in #54.
    *** Error in `./siteupdate': free(): invalid pointer: 0x00007ffdd02ca250 ***, etc.
    I'm not deleteing anything, other than the threads themselves after completion, which should not be a problem. Variables -- strings & standard containers for the most part -- just reach the end of their lifespans & are destructed however C++ destroys them.
    Either something wrong with my RAM, or something is getting fouled up behind the scenes in ways I can't quite see by multiple threads writing to stuff.
    The saner approach would be to assume the latter if there's something I've confirmed needs fixing.

    Address #56, keep testing, and see where that leads me.

  9. changed the title [-]std::length_error / basic_string::_M_create[/-] [+]crash when Writing near-miss point merged wpt files[/+] on Jan 25, 2019
  10. yakra commented on Jan 26, 2019

    @yakra
    OwnerAuthor

    Makes sense to take the 3 current bugs chronologically:
    #44, #55, #54

  11. yakra commented on Jan 26, 2019

    @yakra
    OwnerAuthor

    Seen 2 core dumps now. In both cases, the pointer is in the stack.
    Are these the pointers to my threads, is deleting them a bad idea?

  12. yakra commented on Jan 26, 2019

    @yakra
    OwnerAuthor

    Ideas:

    • Iterate by something other than std::list<Route*> *all_routes?
      • interleaved vector?
      • HighwaySystem per thread?
    • Try not deleting threads. No dice.
    • Do wpt files get written?
      • Learn awk... Only relaunch siteupdate when there's no crash
      • ...or do it manually. Yes, files get written.
    • Memtest86
      • PNY 2BG: 9:33 wall time, 19(?) passes, 0 errors
      • 2x1GB Samsung not tested yet
  13. yakra commented on Jan 26, 2019

    @yakra
    OwnerAuthor

    for posterity:

    		for (unsigned int t = 0; t < args.numthreads; t++)
    		{	thr[t] = new thread(NmpMergedThread, &all_routes, &list_mtx, &args.nmpmergepath);
    			printf("thr[%02i]: ", t);
    			cout << thr[t];
    			if (t%2 == 0)	cout << '\t';
    			else		cout << '\n';
    		}
    		if (args.numthreads%2 == 1) cout << '\n';
  14. yakra commented on Jan 26, 2019

    @yakra
    OwnerAuthor

    Seems one time I saw something funky where a while (foo->size()) loop would continue, size would then be 0, and wacky antics would ensue upon trying to construct an object from the front.
    But this construction should happen (and fail) before all_routes->pop_front(). We're inside a locked mutex.
    I'll try different ways of iterating anyway; I'm running out of ideas...

  15. yakra commented on Jan 26, 2019

    @yakra
    OwnerAuthor

    Current hypothesis, here's what's going on:

    void NmpMergedThread
    ( std::list<Route*> *all_routes,
      std::mutex *mtx,
      std::string *nmpmergepath
    )
    { while (all_routes->size())			// 2 or more threads see size() of 1, and enter the while loop
      { mtx->lock();				// Thread 1 gets here first, locks mtx, and does its thing
        Route *r(all_routes->front());		// Thread 2 gets here, still thinking size() is 1, and that there are objects in all_routes
    						// undefined behavior when trying to access front()
        all_routes->pop_front();			// More undefined behavior due to empty container
    						// Maybe trying to free an invalid pointer?
    						// I don't know man, I didn't do it.
        mtx->unlock();
        r->write_nmp_merged
          (*nmpmergepath + "/" + r->region->code);
      }
    }

    If that's the case, I have not solved the problem but only made it less probable, changing to:

    void NmpMergedThread
    ( std::list<HighwaySystem*> *hs_list,
      std::mutex *mtx,
      std::string *nmpmergepath
    )
    { while (hs_list->size())			// 2 or more threads see size() of 1, and enter the while loop
      { mtx->lock();				// Thread 1 gets here first, locks mtx, and does its thing
        HighwaySystem *h(hs_list->front());		// Thread 2 gets here, still thinking size() is 1, and that there are objects in hs_list
    						// undefined behavior when trying to access front()
        hs_list->pop_front();			// More undefined behavior due to empty container
    						// Maybe trying to free an invalid pointer?
    						// I don't know man, I didn't do it.
        mtx->unlock();
        for (Route &r : h->route_list)
          r.write_nmp_merged
    	(*nmpmergepath + "/" + r.region->code);
      }
    }

    Thus it may be a bit premature to close this issue, even though I've not yet observed crashes, in 121 trials w/8 threads so far.

    Solving the problem may be as simple as putting in another check, an if (foo->size()) once the mutex is locked.
    I may be better off looking into that while looking into the Computing stats crash (#54), the only really visible failure mode at the moment.

  16. yakra commented on Jan 27, 2019

    @yakra
    OwnerAuthor

    Above hypothesis checks out; if statements appear to have stopped crashes in other threads.
    Even with no further crashes in several hundred more runs, this is the safe course of action to take.

  17. yakra commented on Jan 27, 2019

    @yakra
    OwnerAuthor

    Related issues:

    #56 ReadWptThread
    #44 NmpMergedThread
    #55 ReadListThread
    #58 ConcAugThread
    #54 ComputeStatsThread
    #59 UserLogThread

  18. yakra commented on Jun 3, 2019

    @yakra
    OwnerAuthor

    It's back!
    Or rather, nothing has changed here in a while IIRC, but running with 16 threads on lab2 gives more opportunity to observe this.
    No core dump or any text in bash to let us know what's going on.

    Edit: Using crashlog.sh on BiggaTomato, no crashes in 100 runs, whereas it's fairly common on lab2. My thinking is that with 16 threads being handled by only 4 cores on BiggaTomato, there's less true parallelism, and less opportunity for wacky hijinks.

  19. reopened this on Jun 3, 2019
  20. yakra commented on Jun 7, 2019

    @yakra
    OwnerAuthor

    Now this is interesting... On lab2, one thread appeared to get caught in an infinite loop, CPU @ 100%, with the other 15 CPUs @ 0%.
    May be best to tackle the other threads before this one...

  21. yakra commented on Jun 23, 2019

    @yakra
    OwnerAuthor

    Changed from a "modify the list" technique to a "modify the iterator" technique.
    Siteupdate has now been running in a loop on lab2 for > 38 hours & 1313 passes now, with no crashes. Going to re-close this.
    See #58 (comment) and forum post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C++bugnmps

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions