[Bug] Cancel requests
Describe the Bug
Try to cancel requests using cancelLoadAll:
loadObject.cancelFn is not a function
TypeError: loadObject.cancelFn is not a function
Steps to Reproduce
- Cancel loading requests with
cancelLoadAll
The current behavior
cancelLoadAll do nothing and an error appears.
The expected behavior
cancelLoadAll cancel all pending requests.
OS
Windows 10
Node version
18.18.2
Browser
Last
If you're using the wadouri image loader, cancelFn is indeed undefined in https://github.com/cornerstonejs/cornerstone3D/blob/4d12d9d2ecf38805e7c9ca7e93bf36372bfe85ff/packages/dicomImageLoader/src/imageLoader/wadouri/loadImage.ts#L53 and https://github.com/cornerstonejs/cornerstone3D/blob/4d12d9d2ecf38805e7c9ca7e93bf36372bfe85ff/packages/dicomImageLoader/src/imageLoader/wadouri/loadImage.ts#L156 .
@sedghi Can you check please?
we haven't implemented cancel (yet), it requires attaching a signal to each request, and sometimes it even doesn't makes sense to cancel for high bandwidth request, but you can look into the nifti loade in cornerstone3D to see how you can implement one
@sedghi any update on this. Can you say why it doesn't make sense to cancel for high bandwidth request, Especially when loading images in MPR with series with more than 1200 plus images it will hang the browser if network is slow. It would be very helpful there is a cancelFn because we can cancel non priority requests based on user scroll event
HOPE THIS WORKAROUND HELPS
/**
- 📌 DICOM Image Loader: Active XHR Tracking & Aborting
- This setup allows us to track active XMLHttpRequests (XHRs) made by the
- DICOM image loader (e.g., WADO-RS) and abort them if needed — for example,
- when a user cancels a study/series load or navigates away.
- ✅ What this does:
-
- Uses
beforeSendto store each XHR byseriesUID
- Uses
-
- Uses
onloadendto remove completed requests from the tracking list
- Uses
-
- Makes it possible to cancel all requests for a specific series
- 🧠 Pair this with a function like
cancelRequestsForSeries(seriesUID) - that calls
.abort()on all stored XHRs for that series. */
dicomImageLoaderInit({ beforeSend: (xhr: XMLHttpRequest, imageId: string) => { // Add auth header xhr.setRequestHeader('Authorization', 'xxxxxxx');
// Extract Series UID from imageId (e.g., "/series/1.2.840...")
const match = imageId.match(/\/series\/([^\/]+)/);
const seriesUID = match ? match[1] : 'unknown';
// Store XHR for potential cancellation later
addToActiveRequest(seriesUID, xhr);
},
onloadend: (event: ProgressEvent, params: any) => { if (params?.xhr && params?.imageId) { // Extract Series UID again const match = params.imageId.match(//series/([^/]+)/); const seriesUID = match ? match[1] : 'unknown';
// Remove completed XHR from tracking
removeFromActiveRequest(seriesUID, params.xhr);
}
}, });