Stabilize Slice 1 local D1 test reads - #51
Merged
Conversation
Stop spawning a second Wrangler D1 CLI against the live local persistence directory. Read DB-only test assertions through test-only Worker routes using the existing D1 binding, eliminating deterministic ECONNRESET flakiness and cutting Slice 1 runtime substantially.
sametbasbug
marked this pull request as ready for review
August 8, 2026 21:31
sametbasbug
added a commit
that referenced
this pull request
Aug 24, 2026
CI'da ara sıra düşen `orbit-slice3-tests.ts` feed testinin kök nedenini
kapatır.
## Belirti
Test ilk `fetch`'te, hiçbir iddiaya varmadan 3-4 ms içinde düşüyordu:
```
TypeError: fetch failed
cause: SocketError: other side closed (UND_ERR_SOCKET)
socket: { bytesWritten: 370, bytesRead: 1631 }
```
## Kök neden
Sunucunun ayakta olmamasıyla ilgili değil. `bytesRead` sıfır değil, yani
o soket
daha önce bir yanıt taşımış: undici'nin havuzundan gelen bir keep-alive
bağlantısı. Sunucu onu kapatmış, istemci ölü sokete yazmış.
İstemcinin kapanmayı neden kaçırdığı: bu dosyalar worker ayaktayken
`spawnSync`
ile ikinci wrangler süreçleri koşturuyor. `spawnSync` olay döngüsünü
saniyelerce
tamamen durduruyor; o sürede undici ne FIN'i işleyebiliyor ne de soketi
havuzdan
atacak zamanlayıcıyı çalıştırabiliyor. Blok biter bitmez gelen `fetch`
aynı
senkron adımda ölü sokete yazıyor.
HTTP/1.1'de yazmadan önce bağlantının açık olduğunu bilmenin yolu yok.
Normal
istemciler bunu tekrar denemeyle örter; testte örtmek istemiyoruz. Kalan
sağlam
seçenek bağlantıyı hiç yeniden kullanmamak.
## Değişiklik
`scripts/support/test-http.ts` (yeni): `useFreshConnectionPerRequest()`
—
`setGlobalDispatcher(new Agent({ pipelining: 0 }))`. `pipelining: 0`
undici'de
keep-alive'ı kapatır; undici dokümanında belgeli yol, tip tanımları da
`keepAlive` yerine bunu öneriyor.
Yerel worker'a HTTP yapan dokuz dosyada import + tek satır çağrı.
`undici`
devDependencies'e eklendi (zaten `overrides`ta pinliydi ve ağaçtaydı;
artık
doğrudan içe aktarıldığı için açıkça duruyor).
İkinci commit bir bekçi ekliyor: `setGlobalDispatcher` global bir
sembole yazıp
Node'un yerleşik `fetch`'inin onu okumasına güveniyor. Bu bağ ileride
koparsa
çağrı sessizce hiçbir şey yapmaz — keep-alive geri gelir, yarış yeniden
açılır ve
hiçbir test kırılmaz, çünkü geri gelen şey ara sıra düşen bir yarış.
Bekçi ayarın
yerleştiğini kurulum anında doğruluyor.
Hiçbir iddia gevşetilmedi, `skip` yok, süre uzatılmadı, retry yok. 126
ekleme,
sıfır silme.
## Ölçüm
`orbit-slice3-tests`, `diagnostics_channel` ile aynı 63 istek üzerinden:
| | bağlantı | istek | yeniden kullanım |
|---|---|---|---|
| önce | 2 | 57 | **55** |
| sonra | 57 | 57 | **0** |
Bekçi mutasyonla sınandı: `setGlobalDispatcher` devre dışı
bırakıldığında
ateşliyor, geri alındığında sessiz.
Çıkış kodu 0 dönenler: `npm run check` (213 dosya, 0 hata), `npm run
test:d1`
(341/341, birkaç kez).
## Dürüstlük notu
Gerçek testi istekle düşüremedik. Mekanizma izole ortamda tetiklendi
(düz fetch
8 turun 4'ünde düşüyor, `pipelining: 0` ile 0/8), ama asıl dosyada yarış
penceresi
zamanlanamayacak kadar dar. Yani: bütün kanıtlarla tutarlı olan
mekanizma
ortadan kaldırıldı; "flake kesin bitti" iddiası bu kadarıyla kanıtlanmış
değil.
Ayrıca workerd'in FIN'i tam olarak neden gönderdiği açık kalıyor.
Düzeltme
tetikleyiciden bağımsız çalışıyor (yeniden kullanılan soket yoksa yarış
da yok),
ama sebep kapatılmış sayılmamalı.
## Ayrı iş olarak kalanlar
- `orbit-slice3-tests.ts:127,134` — worker ayaktayken aynı persist
dizinine
ikinci wrangler süreci. Bu kalıp #51'de slice1'den deterministik
ECONNRESET
sebebi olarak kaldırılmıştı, burada kalmış; bu flake'in ön koşulu olan
bloklamayı da o yaratıyor.
- `waitForWorker` ilk 200'ü hazır sayıyor; sonradan bir yeniden başlatma
olursa
fark edilmez.
- Altı test dosyası ortak dev registry'ye aynı worker adıyla yazıyor.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wrangler d1 executeprocess while the Slice 1wrangler devworker is live__test/*routes on the same Worker/D1 bindingqueryDatabase()callsWhy
The second Wrangler process against the same local persistence directory caused deterministic/flaky
ECONNRESETfailures in the sign-in trace tests. It also added ~26 seconds to the suite.Validation
npm run check: 0 errors, 0 warnings (2 pre-existing hints)No production HTTP/API behavior is changed; the new routes exist only in the dedicated Slice 1 test worker.