         guard let sessionTask = self.task(for: task) else {
             return
         }
-        // The lock should be already acquired in the session delegate queue
-        // by the caller `urlSession(_:task:didCompleteWithError:)`.
-        remove(task, acquireLock: false)
+        remove(task)
         sessionTask.onTaskDone.call((result, Array(sessionTask.callbacks)))
     }
 }


    private func task(for task: URLSessionTask) -> SessionDataTask? {

        lock.lock()
        defer { lock.unlock() }

        guard let url = task.originalRequest?.url else {
            return nil
        }
        guard let sessionTask = tasks[url] else {
            return nil
        }

            // No other callbacks waiting, we can clear the task now.
            if !task.containsCallbacks {
                let dataTask = task.task
                self.remove(dataTask)
            }
        }
        let token = task.addCallback(callback)
