<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Network Session: PendingDownload is always nullptr in DownloadManager::dataTaskBecameDownloadTask"
   href="https://bugs.webkit.org/show_bug.cgi?id=163006">163006</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Network Session: PendingDownload is always nullptr in DownloadManager::dataTaskBecameDownloadTask
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>WebKit Local Build
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>WebKit2
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>cgarcia&#64;igalia.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>achristensen&#64;apple.com, beidson&#64;apple.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I'm not sure when dataTaskBecameDownloadTask() is called exactly in Mac, but it seems to me that PendingDownload is always nullptr at that point. Here are the steps for downloads started with startDownload and convertTaskToDownload:

1- DownloadManager::startDownload()
  m_pendingDownloads.add(downloadID, PendingDownload())

2- PendingDownload()
  m_networkLoad(NetworkLoad())
  set pending download ID, pending download and suggested filename on new NetworkLoad

3- NetworkLoad::resume()
  Starts the load normally until receiving the response

4- NetworkLoad::didReceiveResponse()
  The task has pending download ID

5- NetworkProcess::findPendingDownloadLocation(task, completionHandler)
  Notifies the download manager that is waiting for the location

6- DownloadManager::willDecidePendingDownloadDestination()
  m_pendingDownloads.take(downloadID)
  m_downloadsWaitingForDestination.set(&lt;task, completionHandler&gt;)
  The pending download is now deleted and its NetworkLoad too.
  Once it has the loation it either cancels the download or continues

7- DownloadManager::continueDecidePendingDownloadDestination
  &lt;task, completionHandler&gt; = m_downloadsWaitingForDestination.take(downloadID)
  completionHandler(PolicyDownload)
  m_downloadsAfterDestinationDecided.set(downloadID, task)

8- DownloadManager::dataTaskBecameDownloadTask(downloadID, download)
  The completionHandler() ended up converting the task to a download, so at some point
  dataTaskBecameDownloadTask is called right after creating the download.
  // This is needed for downloads started with startDownload, otherwise it will return nullptr.
  m_pendingDownloads.take(downloadID)
  // This is needed for downloads started with convertTaskToDownload, otherwise it will return nullptr.
  m_downloadsAfterDestinationDecided.take(downloadID)

At this point m_pendingDownloads is supposed to contain the download, because it was started by DownloadManager::startDownload(), but the download was removed from m_pendingDownloads at step 6.
If the completionHandler calls dataTaskBecameDownloadTask() then m_downloadsAfterDestinationDecided doesn't contain the download yet either, so both are indeed nullptr. If it's supposed to happen asynchronously then we indeed have a task even when this was not started by convertTaskToDownload.

1- NetworkLoad()::resume()
  Starts the load normally until policy checker converts the load into a download

2- NetworkLoad::convertTaskToDownload(downloadID, request, response)
  Sets pending download ID to the the task

3- NetworkProcess::findPendingDownloadLocation(task, completionHandler)
  Notifies the download manager that is waiting for the location

The next steps are exactly the same, with the difference that in this case m_pendingDownloads will not contain a PendingDownload for the downloadID, but in both cases we have a NetworkDataTask.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>