MCPcopy Create free account
hub / github.com/easyp-tech/server / probeCommitID

Method probeCommitID

internal/connect/commits.go:1000–1081  ·  view source on GitHub ↗

probeCommitID resolves a Download commit_id (= git sha) that was neither minted in-session nor recoverable by the single-module fallback, by asking each configured source whether it owns the sha. A git sha is unique to one repo, so at most one source succeeds — no cross-module ambiguity. On hit the

(ctx context.Context, sha string)

Source from the content-addressed store, hash-verified

998// disconnecting client bounds the fan-out; each per-source call additionally
999// gets its own timeout (probeTimeout).
1000func (h *commitServiceHandler) probeCommitID(ctx context.Context, sha string) (*moduleRef, bool) {
1001 if sha == "" || h.missCached(sha) {
1002 return nil, false
1003 }
1004 // Re-check commitMap under the lock: a concurrent resolver may have
1005 // already registered this sha while we were waiting on the semaphore.
1006 h.commitMu.RLock()
1007 ref, already := h.commitMap[sha]
1008 h.commitMu.RUnlock()
1009 if already {
1010 r := ref
1011 return &r, true
1012 }
1013
1014 // Bound concurrent probes so a flood of distinct unknown shas cannot
1015 // amplify to unbounded upstream load. Non-blocking acquire: if the cap is
1016 // reached, decline (the caller 400s; the client retries and hits the
1017 // negative cache only after a probe eventually runs).
1018 if h.probeSem != nil {
1019 select {
1020 case h.probeSem <- struct{}{}:
1021 defer func() { <-h.probeSem }()
1022 default:
1023 return nil, false
1024 }
1025 }
1026
1027 sources := h.api.repo.Repositories()
1028 if len(sources) == 0 {
1029 return nil, false
1030 }
1031
1032 type probeResult struct {
1033 ref moduleRef
1034 ok bool
1035 }
1036 // Buffered enough to never block a successful goroutine; first success wins.
1037 results := make(chan probeResult, len(sources))
1038 // transient is set if any source returned a transient error (timeout /
1039 // cancellation / network). In that case the all-fail result is
1040 // inconclusive and must NOT be negative-cached — a brief upstream outage
1041 // should not make a real sha unavailable for ProbeNegativeTTL.
1042 var transient atomic.Bool
1043 var wg sync.WaitGroup
1044 for _, s := range sources {
1045 wg.Add(1)
1046 go func(s source.Source) {
1047 defer wg.Done()
1048 pctx, cancel := context.WithTimeout(ctx, h.probeTimeout)
1049 defer cancel()
1050 meta, err := s.GetMeta(pctx, sha)
1051 if err != nil {
1052 if isTransientErr(err) {
1053 transient.Store(true)
1054 }
1055 return
1056 }
1057 if meta.Commit == "" {

Calls 8

missCachedMethod · 0.95
registerResolvedMethod · 0.95
rememberMissMethod · 0.95
isTransientErrFunction · 0.85
RepositoriesMethod · 0.65
GetMetaMethod · 0.65
OwnerMethod · 0.65
RepoNameMethod · 0.65