Repository navigation
feat(upload): migrate file parameter upload to Connect-RPC FileParameterUploadService with chunked uploader and async verifier - #898
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a generic chunked file upload mechanism and background task manager to replace the previous direct file upload endpoint. Specifically, it adds a reusable TTLCleaner for expiring resources, an AsyncTaskManager for coordinating background tasks with memoization and cancellation, and a new Connect-RPC FileParameterUploadService with corresponding frontend client updates. The ImportSessionManager has also been refactored to leverage the new generic ChunkSessionManager. Feedback on these changes includes addressing a potential integer overflow vulnerability in the chunk boundary validation, removing dead code such as the unused done channel in taskFlight and the unreferenced validateReceivedRanges helper, and using a custom CancellationError instead of DOMException in the frontend uploader to handle aborts cleanly.
d2be440 to
d4bbb9c
Compare
…, and cancellation
Summary
This PR migrates the file upload mechanism in KHI from the legacy monolithic REST endpoint (
POST /api/v3/upload) to a Protobuf / Connect-RPC service (FileParameterUploadService). It introduces a generic chunked upload manager with disk staging, a generic asynchronous task runner (AsyncTaskManager/DoAsyncOrGet) for non-blocking file verification, and a unified frontend chunked upload client with concurrency control.Background & Motivation
DoAsyncOrGetdecouples file integrity verification into asynchronous background jobs with automatic cancellation upon dependency/hash changes, memoizing results for instant polling.API Endpoint Changes
POST/api/v3/uploadPOST/api.v1.FileParameterUploadService/StartFileUploadPOST/api.v1.FileParameterUploadService/UploadFileChunkPOST/api.v1.FileParameterUploadService/CompleteFileUploadPOST/api.v1.FileParameterUploadService/AbortFileUploadKey Changes
1. Protobuf (
proto/api/v1/file_parameter_upload.proto)FileParameterUploadServicewithStartFileUpload,UploadFileChunk,CompleteFileUpload, andAbortFileUpload.make build-proto).2. Go Backend
pkg/common/ttlcleaner:TTLCleaner[K comparable]utility andExpirableTarget[K]interface for automated TTL-based resource eviction.pkg/server/chunkedupload:range.go:ByteRangestruct andValidateReceivedRangesfor byte interval coverage validation.session.go:ChunkSessionmodel and default constants/errors.manager.go:ChunkSessionManagerimplementingttlcleaner.ExpirableTarget[string]with thread-safe file chunk writing (WriteAt).pkg/core/inspection/asynctask:AsyncTaskManager[K comparable, T any]providingDoAsyncOrGetwith context cancellation on input key change, background task execution, and result memoization.pkg/server/upload:UploadFileStoreto useAsyncTaskManagerfor non-blocking asynchronous verification.FileParameterUploadManagercoordinating Connect sessions withUploadFileStore.pkg/server/api/v1&pkg/core/init/default:FileParameterUploadServiceServerConnect handler and registered it into the Gin router.POST /api/v3/uploadroute frompkg/server/server.go.pkg/server/importinspection:ImportSessionManagerto delegate chunked storage and range validation tochunkedupload.ChunkSessionManager.3. Angular Frontend
chunked-uploader.ts:executeChunkedUploadhelper handling file slicing, concurrent chunk uploading, progress reporting, and cancellation.FileParameterUploadClientService:FileParameterUploadService.KHIServerFileUploader:FileParameterUploadClientService.ImportInspectionClientService:executeChunkedUpload.BackendAPI&BackendAPIService:uploadFilemethod.Verification
make test-gopassed across all packages.make test-webpassed (743/743 tests).make build-webandmake build-storybookpassed.make lint-go,make lint-web,make format-go,make format-web, andmake pre-commitpassed with 0 issues.