Keep normal staff roster lookups within the bounded skin concurrency limit

This commit is contained in:
Dev 2026-11-06 09:57:11 +01:00
commit 5bfdfee526
3 changed files with 9 additions and 4 deletions

View file

@ -18,13 +18,13 @@ Floodgate UUIDs with zero high64bits are converted to unsigned decimal XUIDs wit
Texture downloads allow only the exact textures.minecraft.net host and bounded hexadecimal texture path; legacy HTTP metadata is upgraded to HTTPS. Non-default ports, userinfo, query strings, fragments, arbitrary hosts and redirects are refused. No user cookies or credentials are forwarded. Metadata is limited to64KiB, PNG bodies to1MB while streaming, and each fetch has a4second timeout. PNG signature, chunk CRCs, header/dimensions, compressed scanline bounds and filters are checked. Standard64x64 and classic legacy64x32 are supported; animated PNG, unknown models/dimensions and legacy slim combinations fall back honestly. PNG parsing is deliberately a bounded skin-format validator, not a general-purpose image decoder.
The shared resolver coalesces concurrent lookups by canonical identity. Each process bounds entries(256), cached PNG bytes(8MiB), pending lookups(8) and uncached provider lookups(60/minute). Positive caches last5minutes for Java and1minute for Bedrock; failures are cached for30seconds. Authenticated preview requests are also capped at60/account/minute with a bounded window map. Existing public avatar/member/roster routes reuse the resolver and retain their previous fallback presentation.
The shared resolver coalesces concurrent lookups by canonical identity. Each process bounds entries(256), cached PNG bytes(8MiB), pending lookups(16) and uncached provider lookups(60/minute). This admits the current eleven-member staff roster on a cold cache. Positive caches last5minutes for Java and1minute for Bedrock; failures are cached for30seconds. Authenticated preview requests are also capped at60/account/minute with a bounded window map. Existing public avatar/member/roster routes reuse the resolver and retain their previous fallback presentation.
## Actual staged checks
- 23 focused checks pass on local Node24:22API/identity/avatar checks and1built-asset regression. The22API checks also pass on deployed-runtime Node22.23.3 in an isolated temporary tree with synthetic accounts/UUIDs/PNG fixtures and mocked remote providers.
- 24 focused checks pass on local Node24:23API/identity/avatar checks and1built-asset regression. The23API checks also pass on deployed-runtime Node22.23.3 in an isolated temporary tree with synthetic accounts/UUIDs/PNG fixtures and mocked remote providers.
- The real CP router was tested with the existing first-login gate. Checks include Java regular/slim/legacy, exact high-XUID round trips, Bedrock empty/malformed responses, identity/model/texture mismatch, unsafe targets, redirects, type/size/CRC errors, timeouts, streaming cancellation, concurrency/cache bounds, opaque URL ownership, auth revocation and link changes during pending work. A model-only change invalidates the skin version even when PNG bytes are identical.
- Broader Node24 comparison: baseline457tests/29failures; candidate477tests/the identical29failing cases,20added passing tests. Existing failures remain unresolved; the full suite is not described as passing. Both broad runs use the same generated static Worker because this package does not change authored web assets.
- Broader Node24 comparison: baseline457tests/29failures; candidate478tests/the identical29failing cases,21added passing tests. Existing failures remain unresolved; the full suite is not described as passing. Both broad runs use the same generated static Worker because this package does not change authored web assets.
- The original static build failed on an internal seal provenance text file. A narrowly scoped packaging fix excludes `assets/seals/*-provenance.txt`; unknown asset types still fail the build. The candidate build succeeds with422embedded assets. Its regression check retains the approved seal image and excludes the internal note. Authored menu files were restored after test builds; the rebuilt static bundle is test evidence, not a production deployment.
No game state, currency, receipts, purchases, entitlements or linked identity records are mutated. No third-party renderer/dependency is added. The three solid-colour PNG test fixtures were generated locally; no real player's skin is used in tests. Merge, guarded rollout, live mount verification and rollback references must be recorded in native316 before completion. This checkpoint is staged only.

View file

@ -69,7 +69,7 @@ async function boundedBytes(response,limit){
try{for(;;){const{done,value}=await reader.read();if(done)break;size+=value.byteLength;if(size>limit){await reader.cancel();throw Error('Skin response too large');}chunks.push(Buffer.from(value));}}finally{reader.releaseLock();}
return Buffer.concat(chunks,size);
}
export function createSkinResolver({fetcher=fetch,now=Date.now,maxEntries=256,maxBytes=8388608,maxPending=8,lookupsPerMinute=60}={}){
export function createSkinResolver({fetcher=fetch,now=Date.now,maxEntries=256,maxBytes=8388608,maxPending=16,lookupsPerMinute=60}={}){
const cache=new Map(),pending=new Map();let total=0,windowEnd=0,lookups=0;
function remember(key,value,ttl){const previous=cache.get(key);total-=previous?.value?.bytes.length||0;cache.delete(key);cache.set(key,{value,until:now()+ttl});total+=value?.bytes.length||0;while(cache.size>maxEntries||total>maxBytes){const key=cache.keys().next().value;total-=cache.get(key).value?.bytes.length||0;cache.delete(key);}}
async function remote(url,kind){

View file

@ -63,6 +63,11 @@ test('concurrent same-identity lookups share work and bounded pending capacity d
const resolver=createSkinResolver({maxPending:1,fetcher:async url=>{calls++;if(String(url).includes('sessionserver')){await gate;return Response.json(javaProfile());}return imageResponse(png);}});
const a=resolver.resolve(javaUuid),b=resolver.resolve(javaUuid);assert.equal(await resolver.resolve(otherUuid),null);release();const results=await Promise.all([a,b]);assert.strictEqual(results[0],results[1]);assert.equal(calls,2);
});
test('a normal eleven-member roster can resolve its cold-cache skins together',async()=>{
const ids=Array.from({length:11},(_,i)=>'11111111-1111-4111-8111-'+String(i+1).padStart(12,'0')),byCompact=new Map(ids.map(id=>[id.replaceAll('-',''),id]));
let release,calls=0;const gate=new Promise(r=>release=r);const resolver=createSkinResolver({fetcher:async url=>{if(String(url).includes('sessionserver')){calls++;await gate;return Response.json(javaProfile(byCompact.get(String(url).split('/').at(-1))));}return imageResponse(png);}});
const requests=ids.map(id=>resolver.resolve(id)),started=calls;release();const skins=await Promise.all(requests);assert.equal(started,11);assert(skins.every(Boolean));
});
test('negative caching expires; lookup budget and entry/byte bounds remain effective',async()=>{
let time=0,calls=0;const missing=createSkinResolver({now:()=>time,lookupsPerMinute:2,fetcher:async()=>{calls++;return Response.json({},{status:404});}});
await missing.resolve(javaUuid);await missing.resolve(javaUuid);assert.equal(calls,1);time=30001;await missing.resolve(javaUuid);assert.equal(calls,2);await missing.resolve(otherUuid);assert.equal(calls,2);time=60001;await missing.resolve(otherUuid);assert.equal(calls,3);