Feature #10978

improve smb cancel support

Added by Gordon Ross 9 months ago. Updated 9 months ago.

Start date:
Due date:
% Done:


Estimated time:


A few improvements to SMB cancel processing.

1: When SMB requests are cancelled, there are several places where a request might block. We'd like an object-oriented cancellation method function that the common code can call to unblock such requests.
Requests that block for a while will install a call-back function that can be used to unblock the request when cancelled.

2: Some of the smbtorture tests we run (i.e. smb2.notify.dir) send an SMB request followed immediately by a cancel. Currently, SMB cancel only works for requests that have started executing (and blocked somewhere) before the SMB cancel is processed.

3: Cancel has an inherent race with the request it applies to, in that one must have decoded enough of the original request so that cancel can identify it by its message ID during cancel processing, even if the original request has not yet been scheduled to run.



Updated by Gordon Ross 9 months ago

  • Description updated (diff)
  • Status changed from New to In Progress
  • Difficulty changed from Medium to Hard

Updated by Gordon Ross 9 months ago

It took a couple tries to get this fixed without breaking various client expectations.
The best and final design for the fix was:

1: When we first receive a request (in the reader thread) walk all the elements of the SMB2 compound, decoding each SMB2 header and keep track of the range of SMB2 message IDs used in the compound. The message ID range used by the compound is recorded in the SMB request (smb2_first_msgid, smb2_total_credits).

2: When a cancel is received, we walk the list of SMB requests for the current session, looking for the SMB request (compound) with a range that contains the SMB message ID specified in the SMB2 Cancel call.
If an SMB message is found and it's state is either "not yet running" or "running", change the state to "cancelled".

3: At various points in SMB command processing (i.e. typically where we're about to block) check the SMB request state, and if the state is now "cancelled", return an the error NT_STATUS_CANCELLED


Updated by Gordon Ross 9 months ago


smbtorture ... smb2.notify.dir
(used to hang, now pass)

Large file copies from Windows (i.e. a DVD image)
with and without terminating the copy after about 50%


Updated by Electric Monk 9 months ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

git commit 5677e04907859594bfe1a95ba3bfdb1629b89dac

commit  5677e04907859594bfe1a95ba3bfdb1629b89dac
Author: Gordon Ross <>
Date:   2019-05-23T02:59:03.000Z

    10978 improve smb cancel support
    Reviewed by: Matt Barden <>
    Reviewed by: Kevin Crowe <>
    Reviewed by: Evan Layton <>
    Reviewed by: Joyce McIntosh <>
    Reviewed by: Yuri Pankov <>
    Approved by: Dan McDonald <>

Also available in: Atom PDF