Skip to content
Myr

Keep the upstream's tokens in a map of finished mints, so no git exchange waits on another's mint

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The git gateway's upstream kept its tokens in an effect Cache with a lookup, built once per isolate: an exchange that missed while another request's mint was under way joined that mint, which ran on the other request's I/O. On Workers that request is cancelled as hung, the same fault the Project DO adapter's listing had, here for concurrent clones or pushes to one repo. Each exchange that misses now mints its own token, and only a finished one is kept, until a minute before it expires, at most 1024 of them, oldest dropped first.

authored by oscabriel · committed by oscabriel · parent 95c7310 · Browse files · 2 files+122 added−43 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+122 added−43 removed

  • tests:+62 added−0 removed
  • other:+60 added−43 removed

2 files+122 added−43 removed

modified:packages/git/src/upstream/repo-host.ts+60 added-43 removed
modified:packages/git/test/upstream.test.ts+62 added
5 unmodified lines
6import {7 DateTime,8 Duration,9 Effect,10 Fiber,11 Layer,12 Option,13 Redacted,14 Ref,15 Stream,16} from "effect";
205 unmodified lines
222 })223 )224 );225226 // On Workers a request that awaits another request's I/O is cancelled as hung,227 // and one whose client left is cancelled where it stands: its mint never ends.228 it.live(229 "never has an exchange wait on a token another exchange is minting",230 () =>231 Effect.gen(function* () {232 const mints = yield* Ref.make(0);233 const requests = yield* Ref.make<readonly Request[]>([]);234235 const stalling = Layer.effect(236 RepoHost,237 Effect.gen(function* () {238 const host = yield* RepoHost;239240 return RepoHost.of({241 ...host,242 mintToken: (name, scope, ttl) =>243 Effect.flatMap(244 Ref.getAndUpdate(mints, (count) => count + 1),245 (count) =>246 count === 0247 ? Effect.never248 : host.mintToken(name, scope, ttl)249 ),250 });251 })252 ).pipe(Layer.provide(RepoHostMemory));253254 const later = yield* Effect.gen(function* () {255 yield* RepoHost.use((host) => host.create(repo)).pipe(Effect.orDie);256257 const upstream = yield* Upstream;258259 const abandoned = yield* Effect.forkChild(260 upstream.exchange(repo, advertise)261 );262263 yield* Effect.yieldNow;264265 const answered = yield* Effect.timeoutOption(266 Effect.as(upstream.exchange(repo, advertise), "answered"),267 "2 seconds"268 );269270 yield* Fiber.interrupt(abandoned);271272 return answered;273 }).pipe(274 Effect.provide(275 UpstreamRepoHost.pipe(276 Layer.provideMerge(Layer.mergeAll(stalling, recording(requests)))277 )278 )279 );280281 expect(later).toStrictEqual(Option.some("answered"));282 expect(yield* Ref.get(mints)).toBe(2);283 })284 );285286 it.effect("calls a request that got no response an UpstreamFailure", () =>287 Effect.gen(function* () {288 const unreachable = Layer.succeed(289 Fetch,
48 unmodified lines