GithubHelp home page GithubHelp logo

Comments (2)

randomthingsandstuff avatar randomthingsandstuff commented on August 19, 2024

updateFromNewState() gets called unconditionally after first hit by updateFile() during startup. If updateFile() errors out, s.lastdata doesn't get populated. This nil pointer gets dereferenced and then crashes. This does not appear affect already running scenario because s.lastdata would have been populated or crashed on first run and error checking is in place that ensures the pointer is not changed if there is an error retrieving or deserializing.

Frame 4: ./stayrtr.go:258 (PC: a242a4)
   253: // Update the state based on the current slurm file and data.
   254: func (s *state) updateFromNewState() error {
   255:         sessid, _ := s.server.GetSessionId(nil)
   256:
   257:         if s.checktime {
=> 258:                 buildtime, err := time.Parse(time.RFC3339, s.lastdata.Metadata.Buildtime)
   259:                 if err != nil {
   260:                         return err
   261:                 }
   262:                 notafter := buildtime.Add(time.Hour * 24)
   263:                 if time.Now().UTC().After(notafter) {
(dlv) print s.lastdata
*github.com/bgp/stayrtr/prefixfile.VRPList nil

Fundamentally, this defect can be fixed either by:

  1. Initializing a placeholder (empty?) structure or
  2. explicitly handling nil pointer scenario and ensure that other uninitialized components (s.lasthash, s.lastchange) are also not problematic

In case # 1, the empty structure could be an empty VRPList. On initialization of a server object, an empty VRPList is created and pointed to via lastdata. Because updatefile() relies on the hash provided in lasthash and the comparison function is bytes.Compare, the empty []byte slice will never compare as equal (until later populated). This results in routineUpdate() retrying based on its existing timers.

In case # 2, updateFromNewState() would check for nil s.lastdata pointer and return an error. This would leave the pointer alone until updateFile() finally gets the file correctly. Other places in code would need to be aware of the possibility of nil-ity to avoid future problems.

To avoid changing more than required and reduce silliness of forgetting nil pointers, I'll use # 1 by instantiating an empty VRPList in the state.lastdata member. It is probably possible to simply change the lastdata to not be a pointer to resolve this issue, but it requires more reading and thinking to be sure of side effects.

from stayrtr.

randomthingsandstuff avatar randomthingsandstuff commented on August 19, 2024

Issue was fixed, but also see now that the refresh time is really too long to wait. By default, it is 1 hour. While it will probably work in an hour, this should probably complete a bit faster.

Since s.lastchange.IsZero() will only be true prior to fetch, check this value and set the refresh to 30 seconds when true.

from stayrtr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.