Skip to content

Commit 3de6bc7

Browse files
committed
fix: docker build cache EOF
1 parent 7bb5428 commit 3de6bc7

File tree

4 files changed

+7
-20
lines changed

4 files changed

+7
-20
lines changed

lib/storage/defineStorageDriver.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export interface StorageDriver {
1919
partNumber: number
2020
data: ReadableStream
2121
chunkStart: number
22-
chunkEnd: number
2322
}) => Promise<{
2423
eTag: string | null
2524
}>

lib/storage/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export interface Storage {
3333
uploadId: number
3434
chunkStream: ReadableStream<Buffer>
3535
chunkStart: number
36-
chunkEnd: number
3736
chunkIndex: number
3837
}) => Promise<void>
3938
commitCache: (uploadId: number | string, size: number) => Promise<void>
@@ -108,7 +107,7 @@ export async function initializeStorage() {
108107
cacheId: uploadId,
109108
}
110109
},
111-
async uploadChunk({ uploadId, chunkStream, chunkStart, chunkEnd, chunkIndex }) {
110+
async uploadChunk({ uploadId, chunkStream, chunkStart, chunkIndex }) {
112111
const upload = await db
113112
.selectFrom('uploads')
114113
.selectAll()
@@ -121,10 +120,6 @@ export async function initializeStorage() {
121120
return
122121
}
123122

124-
if (chunkEnd === chunkStart) {
125-
throw new Error('Chunk end must be greater than chunk start')
126-
}
127-
128123
const partNumber = chunkIndex + 1
129124

130125
const objectName = getObjectNameFromKey(upload.key, upload.version)
@@ -135,7 +130,6 @@ export async function initializeStorage() {
135130
partNumber,
136131
data: chunkStream,
137132
chunkStart,
138-
chunkEnd,
139133
})
140134
await db
141135
.insertInto('upload_parts')
@@ -152,15 +146,14 @@ export async function initializeStorage() {
152146
driverUploadId: upload.driver_upload_id,
153147
uploadId,
154148
chunkStart,
155-
chunkEnd,
156149
partNumber,
157150
},
158151
err,
159152
)
160153
throw err
161154
}
162155

163-
logger.debug('Upload:', { uploadId, chunkStart, chunkEnd, partNumber })
156+
logger.debug('Upload:', { uploadId, chunkStart, partNumber })
164157
},
165158
async commitCache(uploadId) {
166159
const upload = await db

routes/_apis/artifactcache/caches/[cacheId].patch.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export default defineEventHandler(async (event) => {
4747
uploadId: cacheId,
4848
chunkStream: stream as ReadableStream<Buffer>,
4949
chunkStart: start,
50-
chunkEnd: end,
5150
chunkIndex,
5251
})
5352
})

routes/upload/[cacheId].put.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Buffer } from 'node:buffer'
2+
import { randomUUID } from 'node:crypto'
23

34
import { z } from 'zod'
45
import { logger } from '~/lib/logger'
@@ -22,6 +23,8 @@ export default defineEventHandler(async (event) => {
2223

2324
if (getQuery(event).comp === 'blocklist') {
2425
setResponseStatus(event, 201)
26+
// prevent random EOF error with in tonistiigi/go-actions-cache caused by missing request id
27+
setHeader(event, 'x-ms-request-id', randomUUID())
2528
return
2629
}
2730

@@ -42,30 +45,23 @@ export default defineEventHandler(async (event) => {
4245
throw createError({ statusCode: 400, statusMessage: 'Request body must be a stream' })
4346
}
4447

45-
const contentLengthHeader = getHeader(event, 'content-length')
46-
const contentLength = Number.parseInt(contentLengthHeader ?? '')
47-
if (!contentLengthHeader || Number.isNaN(contentLength)) {
48-
logger.debug("Upload: 'content-length' header not found")
49-
throw createError({ statusCode: 400, statusMessage: "'content-length' header is required" })
50-
}
51-
5248
const userAgent = getHeader(event, 'user-agent')
5349

5450
// 1 MB for docker buildx
5551
// 64 MB for everything else
5652
const chunkSize = userAgent && userAgent.startsWith('azsdk-go-azblob') ? MB : 64 * MB
5753
const start = chunkIndex * chunkSize
58-
const end = start + contentLength - 1
5954

6055
const adapter = await useStorageAdapter()
6156
await adapter.uploadChunk({
6257
uploadId: cacheId,
6358
chunkStream: stream as ReadableStream<Buffer>,
6459
chunkStart: start,
65-
chunkEnd: end,
6660
chunkIndex,
6761
})
6862

63+
// prevent random EOF error with in tonistiigi/go-actions-cache caused by missing request id
64+
setHeader(event, 'x-ms-request-id', randomUUID())
6965
setResponseStatus(event, 201)
7066
})
7167

0 commit comments

Comments
 (0)