This is an automated email from the ASF dual-hosted git repository.

dgelinas pushed a commit to branch 3.1.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/3.1.x by this push:
     new 462ab7f  Fix TM nil panic in CRConfig validation (#3877)
462ab7f is described below

commit 462ab7faf0502a79a24e3261fa9fc9844633148c
Author: Hank Beatty <[email protected]>
AuthorDate: Fri Aug 16 09:47:09 2019 -0400

    Fix TM nil panic in CRConfig validation (#3877)
    
    (cherry picked from commit 4d86b1d10ecb32c5d52e1feddcb512d74aab208c)
    
    This fixes a bug where TM crashes when PostgreSQL is unavailable
    
    Updated Changelog
---
 CHANGELOG.md                     |  3 +--
 traffic_monitor/towrap/towrap.go | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index db4aaf7..ecb2ece 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,9 +9,8 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 ### Changed
 - Fix TO Servers validation to allow "" ipv6
 
-
 ### Fixed
-
+- Fixed a bug where TM crashes when PostgreSQL is unavailable
 
 ## [3.0.1] - 2019-04-09
 ### Added
diff --git a/traffic_monitor/towrap/towrap.go b/traffic_monitor/towrap/towrap.go
index 76dbedf..67a13f6 100644
--- a/traffic_monitor/towrap/towrap.go
+++ b/traffic_monitor/towrap/towrap.go
@@ -196,8 +196,16 @@ func (s TrafficOpsSessionThreadsafe) CRConfigHistory() 
[]CRConfigStat {
 }
 
 func (s *TrafficOpsSessionThreadsafe) CRConfigValid(crc *tc.CRConfig, cdn 
string) error {
+       if crc.Stats.CDNName == nil {
+               return errors.New("CRConfig.Stats.CDN missing")
+       }
+       if crc.Stats.DateUnixSeconds == nil {
+               return errors.New("CRConfig.Stats.Date missing")
+       }
+
        // Note this intentionally takes intended CDN, rather than trusting 
crc.Stats
        lastCrc, lastCrcTime, lastCrcStats := s.lastCRConfig.Get(cdn)
+
        if lastCrc == nil {
                return nil
        }
@@ -205,12 +213,13 @@ func (s *TrafficOpsSessionThreadsafe) CRConfigValid(crc 
*tc.CRConfig, cdn string
                log.Warnln("TrafficOpsSessionThreadsafe.CRConfigValid returning 
no error, but last CRConfig Date was missing!")
                return nil
        }
+       if lastCrcStats.CDNName == nil {
+               log.Warnln("TrafficOpsSessionThreadsafe.CRConfigValid returning 
no error, but last CRConfig CDN was missing!")
+               return nil
+       }
        if *lastCrcStats.CDNName != *crc.Stats.CDNName {
                return errors.New("CRConfig.Stats.CDN " + *crc.Stats.CDNName + 
" different than last received CRConfig.Stats.CDNName " + *lastCrcStats.CDNName 
+ " received at " + lastCrcTime.Format(time.RFC3339Nano))
        }
-       if crc.Stats.DateUnixSeconds == nil {
-               return errors.New("CRConfig.Stats.Date missing")
-       }
        if *lastCrcStats.DateUnixSeconds > *crc.Stats.DateUnixSeconds {
                return errors.New("CRConfig.Stats.Date " + 
strconv.FormatInt(*crc.Stats.DateUnixSeconds, 10) + " older than last received 
CRConfig.Stats.Date " + strconv.FormatInt(*lastCrcStats.DateUnixSeconds, 10) + 
" received at " + lastCrcTime.Format(time.RFC3339Nano))
        }

Reply via email to