diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-09-19 18:18:19 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-09-19 21:10:23 +0430 |
commit | 81a0301d4dd761bc4fd0dd077877ab95c6957364 (patch) | |
tree | 966082bdb5290457db52c32ed4116c11a79c7579 /Userland | |
parent | 436693c0c907b9a15bd6cccc07304e6332bc7b7b (diff) | |
download | serenity-81a0301d4dd761bc4fd0dd077877ab95c6957364.zip |
LibCore+RequestServer: Ignore callbacks for cancelled network jobs
Also cancel the jobs when they're destroyed.
This makes sure that jobs whose owners have discarded don't end up
crashing because of a did_fail().
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibCore/NetworkJob.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/RequestServer/GeminiRequest.cpp | 2 | ||||
-rw-r--r-- | Userland/Services/RequestServer/HttpRequest.cpp | 2 | ||||
-rw-r--r-- | Userland/Services/RequestServer/HttpsRequest.cpp | 2 |
4 files changed, 12 insertions, 3 deletions
diff --git a/Userland/Libraries/LibCore/NetworkJob.cpp b/Userland/Libraries/LibCore/NetworkJob.cpp index dd8b15ed00..c79f3085b4 100644 --- a/Userland/Libraries/LibCore/NetworkJob.cpp +++ b/Userland/Libraries/LibCore/NetworkJob.cpp @@ -29,6 +29,9 @@ void NetworkJob::shutdown() void NetworkJob::did_finish(NonnullRefPtr<NetworkResponse>&& response) { + if (is_cancelled()) + return; + // NOTE: We protect ourselves here, since the on_finish callback may otherwise // trigger destruction of this job somehow. NonnullRefPtr<NetworkJob> protector(*this); @@ -42,6 +45,9 @@ void NetworkJob::did_finish(NonnullRefPtr<NetworkResponse>&& response) void NetworkJob::did_fail(Error error) { + if (is_cancelled()) + return; + // NOTE: We protect ourselves here, since the on_finish callback may otherwise // trigger destruction of this job somehow. NonnullRefPtr<NetworkJob> protector(*this); @@ -55,6 +61,9 @@ void NetworkJob::did_fail(Error error) void NetworkJob::did_progress(Optional<u32> total_size, u32 downloaded) { + if (is_cancelled()) + return; + // NOTE: We protect ourselves here, since the callback may otherwise // trigger destruction of this job somehow. NonnullRefPtr<NetworkJob> protector(*this); diff --git a/Userland/Services/RequestServer/GeminiRequest.cpp b/Userland/Services/RequestServer/GeminiRequest.cpp index d98feb0546..9b087d783b 100644 --- a/Userland/Services/RequestServer/GeminiRequest.cpp +++ b/Userland/Services/RequestServer/GeminiRequest.cpp @@ -58,7 +58,7 @@ GeminiRequest::~GeminiRequest() { m_job->on_finish = nullptr; m_job->on_progress = nullptr; - m_job->shutdown(); + m_job->cancel(); } NonnullOwnPtr<GeminiRequest> GeminiRequest::create_with_job(Badge<GeminiProtocol>, ClientConnection& client, NonnullRefPtr<Gemini::GeminiJob> job, NonnullOwnPtr<OutputFileStream>&& output_stream) diff --git a/Userland/Services/RequestServer/HttpRequest.cpp b/Userland/Services/RequestServer/HttpRequest.cpp index 0a13a520ca..a0f29f2e3c 100644 --- a/Userland/Services/RequestServer/HttpRequest.cpp +++ b/Userland/Services/RequestServer/HttpRequest.cpp @@ -22,7 +22,7 @@ HttpRequest::~HttpRequest() { m_job->on_finish = nullptr; m_job->on_progress = nullptr; - m_job->shutdown(); + m_job->cancel(); } NonnullOwnPtr<HttpRequest> HttpRequest::create_with_job(Badge<HttpProtocol>&&, ClientConnection& client, NonnullRefPtr<HTTP::HttpJob> job, NonnullOwnPtr<OutputFileStream>&& output_stream) diff --git a/Userland/Services/RequestServer/HttpsRequest.cpp b/Userland/Services/RequestServer/HttpsRequest.cpp index 95c78157ba..f3f537705c 100644 --- a/Userland/Services/RequestServer/HttpsRequest.cpp +++ b/Userland/Services/RequestServer/HttpsRequest.cpp @@ -27,7 +27,7 @@ HttpsRequest::~HttpsRequest() { m_job->on_finish = nullptr; m_job->on_progress = nullptr; - m_job->shutdown(); + m_job->cancel(); } NonnullOwnPtr<HttpsRequest> HttpsRequest::create_with_job(Badge<HttpsProtocol>&&, ClientConnection& client, NonnullRefPtr<HTTP::HttpsJob> job, NonnullOwnPtr<OutputFileStream>&& output_stream) |