Skip to content

Commit

Permalink
Prevent concurrent read and writes to visibility map. (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Nov 1, 2022
1 parent 2884864 commit fe1e475
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/sources/github/github.go
Expand Up @@ -62,6 +62,7 @@ type Source struct {
resumeInfoMutex sync.Mutex
resumeInfoSlice []string
apiClient *github.Client
mu sync.Mutex
publicMap map[string]source_metadatapb.Visibility
sources.Progress
}
Expand Down Expand Up @@ -177,12 +178,18 @@ func (s *Source) Init(aCtx context.Context, name string, jobID, sourceID int64,
}

func (s *Source) visibilityOf(repoURL string) (visibility source_metadatapb.Visibility) {
if visibility, exists := s.publicMap[repoURL]; exists {
s.mu.Lock()
visibility, ok := s.publicMap[repoURL]
s.mu.Unlock()
if ok {
return visibility
}

visibility = source_metadatapb.Visibility_public
defer func() {
s.mu.Lock()
s.publicMap[repoURL] = visibility
s.mu.Unlock()
}()
log.Debugf("Checking public status for %s", repoURL)
u, err := url.Parse(repoURL)
Expand Down

0 comments on commit fe1e475

Please sign in to comment.