LdapAllGroupsSyncWorker fails when group has a nil ldap_sync_last_sync_at

ZenDesk: https://gitlab.zendesk.com/agent/tickets/117660

Somehow an LDAP group got into a state where it looks like it was started, but ldap_sync_last_sync_at was nil, resulting in the following failures:

2019-03-28_04:00:43.33413 2019-03-28T04:00:43.333Z 942 TID-otzz24a5y WARN: {"context":"Job raised exception","job":{"queue":"cronjob:ldap_all_groups_sync","args":[],"class":"LdapAllGroupsSyncWorker","retry":false,"queue_namespace":"cronjob","jid":"708f6220943ef9577038f624","created_at":1553745614.2891605,"correlation_id":"eb30af4f-5db2-41fc-b6df-d5ef3a0e9b59","enqueued_at":1553745614.2951941},"jobstr":"{\"queue\":\"cronjob:ldap_all_groups_sync\",\"args\":[],\"class\":\"LdapAllGroupsSyncWorker\",\"retry\":false,\"queue_namespace\":\"cronjob\",\"jid\":\"708f6220943ef9577038f624\",\"created_at\":1553745614.2891605,\"correlation_id\":\"eb30af4f-5db2-41fc-b6df-d5ef3a0e9b59\",\"enqueued_at\":1553745614.2951941}"} 
2019-03-28_04:00:43.33530 2019-03-28T04:00:43.334Z 942 TID-otzz24a5y WARN: NoMethodError: undefined method `<' for nil:NilClass 
2019-03-28_04:00:43.33532 2019-03-28T04:00:43.334Z 942 TID-otzz24a5y WARN: /opt/gitlab/embedded/service/gitlab-rails/ee/lib/ee/gitlab/auth/ldap/sync/group.rb:69:in `fail_stuck_group' 
2019-03-28_04:00:43.33533 /opt/gitlab/embedded/service/gitlab-rails/ee/lib/ee/gitlab/auth/ldap/sync/group.rb:58:in `ldap_sync_ready?' 
2019-03-28_04:00:43.33533 /opt/gitlab/embedded/service/gitlab-rails/ee/lib/ee/gitlab/auth/ldap/sync/group.rb:40:in `execute' 
2019-03-28_04:00:43.33534 /opt/gitlab/embedded/service/gitlab-rails/ee/lib/ee/gitlab/auth/ldap/sync/groups.rb:55:in `block in sync_groups' 
2019-03-28_04:00:43.33534 /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.1/lib/active_record/relation/delegation.rb:38:in `each' 
2019-03-28_04:00:43.33535 /opt/gitlab/embedded/lib/ruby/gems/2.5.0/gems/activerecord-5.0.7.1/lib/active_record/relation/delegation.rb:38:in `each'

I'm not sure how this can occur because ee/app/models/ee/group.rb, the group should only transition to started and update ldap_sync_last_sync_at:

        after_transition ready: :started do |group, _|
          group.ldap_sync_last_sync_at = DateTime.now
          group.save
        end

We could guard against a nil value, but I don't quite get how this can happen.

@dblessing Have you seen this before?

Assignee Loading
Time tracking Loading