cornerstone3D icon indicating copy to clipboard operation
cornerstone3D copied to clipboard

[Bug] Cancel requests

Open Sergey1888888 opened this issue 1 year ago • 3 comments

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

  1. 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

Sergey1888888 avatar Mar 11 '24 14:03 Sergey1888888

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 .

abustany avatar Mar 14 '24 14:03 abustany

@sedghi Can you check please?

Sergey1888888 avatar Mar 20 '24 14:03 Sergey1888888

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 avatar Mar 20 '24 16:03 sedghi

@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

AlbinManentia avatar Apr 11 '25 07:04 AlbinManentia

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 beforeSend to store each XHR by seriesUID
    • Uses onloadend to remove completed requests from the tracking list
    • 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);
}

}, });

AlbinManentia avatar Apr 11 '25 11:04 AlbinManentia